簡體   English   中英

無法在Android應用中自定義AppTheme for action bar

[英]Unable to customize AppTheme for action bar in Android app

我正在嘗試自定義操作欄。 我之前也做過,但我現在無法做到。 不知道我哪里出錯了。

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="android:actionBarStyle">@style/MyActionBar</item>
</style>

<style name="MyActionBar"
    parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
    <item name="android:background">@drawable/actionbar_gradient</item>
</style>

這是我正在添加的drawable

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient
        android:angle="270"
        android:startColor="#d6ece542"
        android:endColor="#fffffdf4"
        />
</shape>

我還在我的清單中的<application>標簽中添加了這個:

android:theme="@style/AppTheme"

但每次我只是得到相同的動作欄(主題的默認值)。 有人能說出什么問題嗎?

另外,我的minSdk版本= 18,目標版本= 21

看起來您正在嘗試將Holo操作欄主題應用於Material AppCompat主題。

一種解決方案是將漸變應用為colorPrimary

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@drawable/actionbar_gradient</item>
</style>

更多自定義屬性: https//developer.android.com/training/material/theme.html#StatusBar

另一種解決方案是切換到Holo主題:

  1. 將您的活動更改為extends Activity
  2. 將您的父主題更改為@android:style/Theme.Holo.Light.DarkActionBar

您可能需要將android:type="linear"到該漸變定義中

<gradient
    android:angle="270"
    android:startColor="#d6ece542"
    android:endColor="#fffffdf4"
    android:type="linear"
    />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM