3

アクションバーシャーロックを使用しています。私のカスタムテーマで

values/styles.xml にこれを入力しました。

<style name="Mytheme" parent="@style/Theme.Sherlock.Light">
    <item name="android:background">@drawable/actionbar_bg</item>
</style>

actionbar_bg

<?xml version="1.0" encoding="utf-8"?>
<gradient xmlns:android="http://schemas.android.com/apk/res/android"
    android:type="linear"
    android:centerX="8%" 
    android:startColor="#969696" 
    android:centerColor="#FFFFFF" 
    android:endColor="#FFFFFFFF" 
    android:angle="270"
/>

マニフェスト

<activity
        android:name="com.example.myapp.Secondactivity"
        android:label="@string/title_activity_second"
         android:theme="@style/Mytheme">
 </activity>

Logcat Error Unable to start activity, android.view.InflateException: Binary XML file line #21: Error inflating class

Android:theme="@style/Mytheme"行を削除すると、アプリは正常に動作します

更新: Android:background を単に「背景」に変更したところ、アプリが強制的に閉じられなくなりました。ただし、グラデーションは適用されません。私が見ることができるのは灰色のアクションバーだけです。

更新 #2

styles.xml を次のように変更

<style name="Mytheme" parent="@style/Theme.Sherlock.Light">
<item name="actionBarStyle">@style/MyActionBarTheme</item>
</style>

<style name="MyActionBarTheme" parent="Widget.Sherlock.ActionBar">
<item name="background">@drawable/actionbar_bg</item>
<item name="android:background">@drawable/actionbar_bg</item>
</style>

マニフェストでは、テーマを android:theme="@style/MyActionBarTheme" と呼びます。

画像でわかるように、グラデーションはアクションバーだけでなくウィンドウ全体に広がっています

ここに画像の説明を入力

4

2 に答える 2

1

このactionbar_bg.xmlを追加

ここに画像の説明を入力

Drawable dr = getResources().getDrawable(R.drawable.actionbar_bg);
getActionBar().setBackgroundDrawable(dr);

actionbar_bg.xml

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <gradient
        android:angle="270"
        android:centerColor="#FFFFFF"
        android:centerX="8%"
        android:endColor="#FFFFFFFF"
        android:startColor="#969696"
        android:type="linear" />

</shape>
于 2013-04-23T11:23:13.487 に答える