【问题标题】:Android L support library Toolbar appears under viewsAndroid L 支持库 Toolbar 出现在views下
【发布时间】:2014-12-29 18:00:29
【问题描述】:

我有一个 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,我应该有一个自定义工具栏作为操作栏。但是,出现的工具栏出现在我在块中添加的片段下。工具栏应该出现在它们上方并将它们向下移动,但现在视图覆盖了操作栏工具栏。这是一个小故障还是我只是忘记了什么?这实际上以前有效,但现在由于某种原因被破坏了。

【问题讨论】:

    标签: java android android-layout material-design


    【解决方案1】:

    Toolbar 需要位于 FrameLayout 之外,这将包含您的 Fragment,如下所示:

    <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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 2015-02-13
      • 1970-01-01
      • 2014-05-06
      相关资源
      最近更新 更多