Android工具栏涵盖内容

时间:2015-02-28 18:23:46

标签: android android-actionbar android-styles android-toolbar

我正在使用新工具栏并将其设置为supportActionBar。我的问题是它覆盖了我的内容。

以下是我用来设置工具栏的代码。

 public void setupNavBar() {
    mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
    if (mToolbar != null) {
        setSupportActionBar(mToolbar);

        mActionBar = getSupportActionBar();
        mActionBar.setDisplayShowHomeEnabled(true);
        mActionBar.setDisplayShowTitleEnabled(false);
    }
}

样式:

    <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
</style>

<style name="ToolBarStyle" parent="">
    <item name="android:elevation">5dp</item>
    <item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
    <item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>

和布局:

<RelativeLayout 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"
tools:context=".MainActivity">

<android.support.v7.widget.Toolbar
    style="@style/ToolBarStyle"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/material_blue_grey_800"
    android:minHeight="@dimen/abc_action_bar_default_height_material"
    android:id="@+id/toolbar_actionbar"

    />

<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#478"
    android:text="@string/hello_world" />

我认为通过调用setSupportActionbar,系统将负责在工具栏视图下方定位内容,但这不是我所看到的。

使用工具栏的正确方法是什么。我有一些活动,我希望工具栏透明,背后的内容和其他我希望它与下面的内容不透明。

由于

2 个答案:

答案 0 :(得分:3)

在textview

中使用以下内容
    <TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#478"
android:text="@string/hello_world"
android:layout_below="@+id/toolbar_actionbar"
/>

答案 1 :(得分:0)

我刚刚遇到了同样的问题。我通过在context_main.xml文件中添加以下两行来修复它:

POJO

赞:

app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.yourappname.MainActivity"
相关问题