gpt4 book ai didi

java - Android L 支持库工具栏出现在 View 下

转载 作者:行者123 更新时间:2023-12-01 12:20:21 25 4
gpt4 key购买 nike

我有一个 mainactivity.xml,它有一个框架布局,里面有一个工具栏

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:ignore="MergeRootFrame" >
<android.support.v7.widget.Toolbar
android:id = "@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
</FrameLayout>

在我的 mainactivity.java 中,我有这个

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

}

根据此处的教程,http://android-developers.blogspot.com/2014/10/appcompat-v21-material-design-for-pre.html ,我应该有一个充当操作栏的自定义工具栏。但是,出现的工具栏出现在我在 block 中添加的 fragment 下方。工具栏应该出现在它们上方并将它们向下移动,但现在 View 覆盖了操作栏工具栏。这是一个小故障还是我只是忘记了什么?这实际上以前有效,但现在由于某种原因被破坏了。

最佳答案

Toolbar 需要位于用于容纳 FragmentFrameLayout 之外,如下所示:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<android.support.v7.widget.Toolbar
android:id = "@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />

<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
tools:ignore="MergeRootFrame" >

</FrameLayout>
</LinearLayout>

关于java - Android L 支持库工具栏出现在 View 下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26708161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com