android - Not able to customize the actionbar manually -
ide used=eclipse juno
api level=14
device's os=4.2.2 jelly bean
i've been trying change background color , text font , font color of action bar using xml file. referred this tutorial , tried got message "unfortunately, myappname has been stopped"
the code using change background is:
res/values/themes.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="mytheme" parent="@android:style/theme.holo.light"> <item name="android:actionbarstyle">@style/myactionbar</item> </style> <style name="myactionbar" parent="@android:style/widget.holo.light.actionbar"> <item name="android:background">#6845db</item> </style> </resources>
after changed app theme in manifest as:-
android:theme="@style/mytheme"
i beginner android development.
error log cat is:-
05-12 14:48:33.866: e/hawaii.gralloc(1449): gralloc alloc flags 933 05-12 14:48:33.886: e/hawaii_egl(1449): abuffer = (480 800) (933) 05-12 14:48:34.257: e/androidruntime(7127): fatal exception: main 05-12 14:48:34.257: e/androidruntime(7127): java.lang.runtimeexception: unable start activity componentinfo{com.decode.timer/com.decode.timer.homescreen}: java.lang.illegalstateexception: need use theme.appcompat theme (or descendant) activity. 05-12 14:48:34.257: e/androidruntime(7127): @ android.app.activitythread.performlaunchactivity(activitythread.java:2255) 05-12 14:48:34.257: e/androidruntime(7127): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2309) 05-12 14:48:34.257: e/androidruntime(7127): @ android.app.activitythread.access$700(activitythread.java:157) 05-12 14:48:34.257: e/androidruntime(7127): @ android.app.activitythread$h.handlemessage(activitythread.java:1289) 05-12 14:48:34.257: e/androidruntime(7127): @ android.os.handler.dispatchmessage(handler.java:99) 05-12 14:48:34.257: e/androidruntime(7127): @ android.os.looper.loop(looper.java:176) 05-12 14:48:34.257: e/androidruntime(7127): @ android.app.activitythread.main(activitythread.java:5317) 05-12 14:48:34.257: e/androidruntime(7127): @ java.lang.reflect.method.invokenative(native method) 05-12 14:48:34.257: e/androidruntime(7127): @ java.lang.reflect.method.invoke(method.java:511) 05-12 14:48:34.257: e/androidruntime(7127): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1102) 05-12 14:48:34.257: e/androidruntime(7127): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:869) 05-12 14:48:34.257: e/androidruntime(7127): @ dalvik.system.nativestart.main(native method) 05-12 14:48:34.257: e/androidruntime(7127): caused by: java.lang.illegalstateexception: need use theme.appcompat theme (or descendant) activity. 05-12 14:48:34.257: e/androidruntime(7127): @ android.support.v7.app.actionbaractivitydelegate.oncreate(actionbaractivitydelegate.java:110) 05-12 14:48:34.257: e/androidruntime(7127): @ android.support.v7.app.actionbaractivitydelegateics.oncreate(actionbaractivitydelegateics.java:57) 05-12 14:48:34.257: e/androidruntime(7127): @ android.support.v7.app.actionbaractivity.oncreate(actionbaractivity.java:99) 05-12 14:48:34.257: e/androidruntime(7127): @ com.decode.timer.homescreen.oncreate(homescreen.java:15) 05-12 14:48:34.257: e/androidruntime(7127): @ android.app.activity.performcreate(activity.java:5326) 05-12 14:48:34.257: e/androidruntime(7127): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1097) 05-12 14:48:34.257: e/androidruntime(7127): @ android.app.activitythread.performlaunchactivity(activitythread.java:2218) 05-12 14:48:34.257: e/androidruntime(7127): ... 11 more 05-12 14:48:34.657: e/hawaii.gralloc(1449): gralloc alloc flags 933 05-12 14:48:34.687: e/hawaii_egl(1449): abuffer = (480 235) (933) 05-12 14:48:34.867: e/android.os.debug(1961): !@dumpstate > dumpstate -k -t -z -d -o /data/log/dumpstate_app_error 05-12 14:48:35.087: e/hawaii.gralloc(1449): gralloc alloc flags 10000b22 05-12 14:48:35.147: e/hawaii.gralloc(1449): gralloc alloc flags 10000b22 05-12 14:48:35.157: e/hawaii_egl(1449): abuffer = (480 800) (10000b22) 05-12 14:48:35.618: e/hawaii.gralloc(1449): gralloc alloc flags 933 05-12 14:48:35.638: e/hawaii_egl(1449): abuffer = (480 235) (933) 05-12 14:48:35.848: e/hawaii.gralloc(1449): gralloc alloc flags 933 05-12 14:48:35.858: e/hawaii_egl(1449): abuffer = (480 235) (933) 05-12 14:48:45.688: e/dalvikvm(7141): adjustadaptivecoef max=4194304, min=1048576, ut=568
your logcat might have given answer
05-12 14:48:34.257: e/androidruntime(7127): caused by: java.lang.illegalstateexception: need use theme.appcompat theme (or descendant) activity.
so need change parent of theme
<style name="mytheme" parent="@style/theme.appcompat.light"> <item name="actionbarstyle">@style/myactionbar</item> </style> <style name="myactionbar" parent="@style/widget.appcompat.actionbar"> <item name="background">#6845db</item> </style>
also, question here might understand why dont need add android:
before item name when using appcompat
for titletextappearance you'd have create style textappearance.appcompat.widget.actionbar.title
parent
<style name="mytitletextappearance" parent="textappearance.appcompat.widget.actionbar.title"> <item name="textcolor">@color/white</item> </style>
then set titletextstyle
in myactionbar
style
<item name="titletextstyle">@style/mytitletextappearance</item>
Comments
Post a Comment