[英]Android - Custom style on Action Bar
是否可以自定義特定活動中操作欄的背景(和標題)? 我做了什么,卻沒有用:
<style name="AppTheme.BenchTheme"> <!-- style of my activity -->
<item name="android:windowBackground">@android:color/holo_blue_light</item>
<item name="android:actionBarStyle">@style/BenchActionBar</item>
</style>
和
<style name="BenchActionBar">
<item name="android:background">@color/colorBench</item>
</style>
我想在我的style.xml中執行此操作。 可能嗎? 我知道我可以通過代碼來做到這一點(使用類似getSupportActionBar()。setBackgroundDrawable(myColor);的方法)...
謝謝
首先讓您的主題從Theme.AppCompat.Light.NoActionBar擴展:
<style name="AppTheme.BenchTheme" parent="Theme.AppCompat.Light.NoActionBar">
然后,在布局中,您可以根據需要添加工具欄,例如:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/kelly_green"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
style="@style/MyToolbarElevation"
>
<android.support.v7.widget.AppCompatTextView
android:id="@+id/txt_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/_2sdp"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="@dimen/_13sdp"
/>
</android.support.v7.widget.Toolbar>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.