我已阅读了几个类似主题,但仍未找到针对此问题的答案。我有一个自定义布局工具栏:工具栏布局与父宽度不匹配
<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
@Yupi <样式名称= “MyToolbar” 父= “ThemeOverlay.AppCompat.Dark.ActionBar”> <项目名称= “机器人:homeAsUpIndicator”> @绘制/ BACK_ARROW – fregomene
您可以手动尝试设置填充是以防万一。 –