[英]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.