[英]Action Bar Background size, Android
我想將操作欄背景顏色更改為自定義顏色。 這是我目前得到的:
如何在整個操作欄寬度上獲得此顏色?
我的動作欄xml
:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#0c555c"
android:gravity="center"
android:id="@+id/action_bar_title"
android:paddingEnd="0dp"
android:paddingStart="0dp"
android:showAsAction="ifRoom">
</RelativeLayout>
onCreate
方法:
RelativeLayout actionBar = (RelativeLayout)findViewById(R.id.action_bar_title);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.action_bar);
請在最后添加這一行。
工具欄父級=(工具欄)actionBar.getParent(); parent.setContentInsetsAbsolute(0,0);
如果您要設計自定義actionBar,則應像這樣編寫代碼:
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#8B58A3")));
LayoutInflater inflater = LayoutInflater.from(this);
@SuppressLint("InflateParams")
View v = inflater.inflate(R.layout.titleview, null);
actionBar.setCustomView(v);
希望能幫助到你 !
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.