[英]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.