[英]Android - Prevent navigation drawer from overlaying title bar
我最近在Android Studio中打開了一個項目,然后選擇了“導航抽屜活動”。 它創建了導航抽屜,只是它以我不喜歡的方式顯示-導航抽屜顯示在標題欄的頂部,例如:
相反,我希望它像:
在此“正確”的示例中,導航欄打開時,標題欄“主頁”與關閉的箭頭一起顯示。
文件來源:
app_bar_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.avi12.soundcloudinstantdownloader.MainActivity"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
</android.support.design.widget.AppBarLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.avi12.soundcloudinstantdownloader.MainActivity"
tools:showIn="@layout/app_bar_main">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:text="What this app can download:"/>
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView"
android:layout_alignStart="@+id/textView"
android:layout_below="@+id/textView"
android:layout_marginLeft="17dp"
android:layout_marginStart="17dp"
android:text="Single tracks"/>
<TextView
android:id="@+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView8"
android:layout_alignStart="@+id/textView8"
android:layout_below="@+id/textView8"
android:text="Playlists, a.k.a albums"/>
<TextView
android:id="@+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView9"
android:layout_alignStart="@+id/textView9"
android:layout_below="@+id/textView9"
android:text="User likes (though only some, due to SoundCloud limiting their API)"/>
<TextView
android:id="@+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView"
android:layout_alignStart="@+id/textView"
android:layout_below="@+id/textView10"
android:layout_marginTop="12dp"
android:text="Instantly download songs by sharing it from SoundCloud with this app!"/>
<TextView
android:id="@+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView11"
android:layout_alignStart="@+id/textView11"
android:layout_below="@+id/textView11"
android:layout_marginTop="18dp"
android:text="Alternatively, you can search the song, and even paste its URL:"/>
<EditText
android:id="@+id/inputDownload"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView12"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignStart="@+id/textView12"
android:layout_below="@+id/textView12"
android:ems="10"
android:hint="Search query or URL"
android:inputType="textUri"
android:singleLine="true"/>
<TextView
android:id="@+id/error"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
/>
</RelativeLayout>
編輯
在Tomer Shemesh的建議之后, <android.support.v7.widget.Toolbar
更改為:
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"
android:layout_marginTop="?attr/actionBarSize"/>
然后,結果是:
因此,目前還沒有解決方案。
除了Tomer建議外, android:layout_marginTop="?attr/actionBarSize"
應該應用於android.support.design.widget.NavigationView
。 我沒有在app_bar_main.xml
看到導航視圖。
添加此選項將使操作欄具有不透明的疊加層。 看起來像不透明覆蓋的圖像
您可以通過將scrimColor
設置為Navigation Drawer Activity
的DrawerLayout
透明來刪除不透明的覆蓋。
mDrawerLayout = (DrawerLayout) getLayoutInflater().inflate(R.layout.activity_refonte_base, null); mDrawerLayout.setScrimColor(ContextCompat.getColor(this,android.R.color.transparent));
現在看起來像這樣。 稀松布顏色為透明的圖像
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.