簡體   English   中英

App force因動作欄主題關閉 - android

[英]App force closes due to actionbar theme - android

我正在使用actionbarsherlock。 用我的自定義主題

在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錯誤無法啟動活動,android.view.InflateException:二進制XML文件行#21:錯誤膨脹類

當我刪除android:theme =“@ style / Mytheme” Line時,該應用程序工作正常

更新:我將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>

在Manifest中我將主題稱為android:theme =“@ style / MyActionBarTheme”。

正如您在圖像中看到的那樣,漸變遍布窗口而不僅僅是動作欄

在此輸入圖像描述

在xml屬性名稱中嘗試不使用android

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

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

android的一個用於本機ActionBar。

添加此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>

暫無
暫無

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

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