我已閱讀了幾個類似主題,但仍未找到針對此問題的答案。我有一個自定義佈局工具欄:工具欄佈局與父寬度不匹配
<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
您可以手動嘗試設置填充是以防萬一。 –