【发布时间】:2017-04-03 19:29:36
【问题描述】:
我已经阅读了几个类似的主题,但仍然没有找到这个问题的答案。我有一个工具栏的自定义布局:
<android.support.design.widget.AppBarLayout android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#99000000">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_transparent"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
app:theme="@style/MyToolbar">
</android.support.v7.widget.Toolbar>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:textAppearance="?android:attr/textAppearanceMedium"
android:layout_centerInParent="true"
android:id="@+id/toolbar_title" />
</RelativeLayout>
这是我的活动代码:
toolbar = (Toolbar) findViewById(R.id.toolbar_transparent);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
我的工具栏仍然有左右填充并且没有填充父宽度。我尝试了各种解决方案。我的代码有什么问题? 问题是我需要我的工具栏是半透明的。这就是为什么我在布局 android:background="#99000000" 中使用这条线。我将它应用于整个布局,我的工具栏变得半透明,但它没有填充父级的宽度。但是,如果我将 android:background="#99000000" 这行应用到整个布局,而是应用到布局中的工具栏小部件,它会正确填充父级,但会失去透明度。这有帮助吗?
【问题讨论】:
-
你的主题 MyToolbar 里面有什么?
-
@Yupi
-
您可以尝试手动将填充设置为零以防万一。
标签: android android-layout android-actionbar android-toolbar