5

Tôi đang sử dụng thanh công cụ mới và đặt nó làm supportActionBar. Vấn đề của tôi là nó bao gồm nội dung của tôi.Thanh công cụ của Android bao gồm nội dung

Đây là mã tôi đang sử dụng để thiết lập thanh công cụ.

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

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

Các Styles:

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

và cách bố trí:

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

Tôi nghĩ rằng bằng cách gọi setSupportActionbar hệ thống sẽ chăm sóc Posi tioning nội dung bên dưới xem thanh công cụ nhưng đó không phải là những gì tôi nhìn thấy.

Cách chính xác để sử dụng thanh công cụ là gì. Tôi có một số hoạt động mà tôi wan thanh công cụ để được minh bạch với nội dung đằng sau nó và những người khác mà tôi muốn nó được đục với nội dung dưới đây.

Cảm ơn

Trả lời

3

sử dụng dưới đây trong 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" 
/> 
Các vấn đề liên quan