textview - Android text styling error - Resource is not a ColorStateList -
i have simple textview:
<textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/app_name" android:textsize="20sp" android:textcolor="@style/basic_text_color" android:layout_gravity="center" android:id="@+id/toolbar_title" />
which @style/basic_text_color color wanted reuse lot of time in app, make app_colors.xml
under values
folder:
<?xml version="1.0" encoding="utf-8"?> <resources> <!-- text colors style--> <style name="basic_text_color" parent="@android:style/textappearance"> <item name="android:textcolor">#ff932e</item> </style> <!-- other color styles--> </resources>
the app compile successfully, whenever executed hang , following error prompted in logcat:
fatal exception: main java.lang.runtimeexception: unable start activity componentinfo{com.example.aaa/com.example.aaa.activity.mainactivity}: android.view.inflateexception: binary xml file line #17: error inflating class textview @ android.app.activitythread.performlaunchactivity(activitythread.java:2100) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2125) @ android.app.activitythread.access$600(activitythread.java:140) @ android.app.activitythread$h.handlemessage(activitythread.java:1227) @ android.os.handler.dispatchmessage(handler.java:99) @ android.os.looper.loop(looper.java:137) @ android.app.activitythread.main(activitythread.java:4898) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:511) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1006) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:773) @ dalvik.system.nativestart.main(native method) caused by: android.view.inflateexception: binary xml file line #17: error inflating class textview @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:704) @ android.view.layoutinflater.rinflate(layoutinflater.java:746) @ android.view.layoutinflater.rinflate(layoutinflater.java:749) @ android.view.layoutinflater.inflate(layoutinflater.java:489) @ android.view.layoutinflater.inflate(layoutinflater.java:396) @ android.view.layoutinflater.inflate(layoutinflater.java:352) @ android.support.v7.app.appcompatdelegateimplv7.setcontentview(appcompatdelegateimplv7.java:249) @ android.support.v7.app.appcompatactivity.setcontentview(appcompatactivity.java:106) @ com.example.aaa.activity.mainactivity.oncreate(mainactivity.java:54) @ android.app.activity.performcreate(activity.java:5206) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1083) @ android.app.activitythread.performlaunchactivity(activitythread.java:2064) ... 11 more caused by: android.content.res.resources$notfoundexception: resource not colorstatelist (color or path): typedvalue{t=0x1/d=0x7f0b0124 a=-1 r=0x7f0b0124} @ android.content.res.resources.loadcolorstatelist(resources.java:2068) @ android.content.res.typedarray.getcolorstatelist(typedarray.java:342) @ android.widget.textview.<init>(textview.java:896) @ android.support.v7.widget.appcompattextview.<init>(appcompattextview.java:44) @ android.support.v7.widget.appcompattextview.<init>(appcompattextview.java:40) @ android.support.v7.internal.app.appcompatviewinflater.createview(appcompatviewinflater.java:103) @ android.support.v7.app.appcompatdelegateimplv7.createview(appcompatdelegateimplv7.java:806) @ android.support.v7.app.appcompatdelegateimplv7.oncreateview(appcompatdelegateimplv7.java:836) @ android.support.v4.view.layoutinflatercompathc$factorywrapperhc.oncreateview(layoutinflatercompathc.java:44) @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:675) ... 22 more
so looks the error here "resource not colorstatelist (color or path): typedvalue{t=0x1/d=0x7f0b0124 a=-1 r=0x7f0b0124}" ...
did styled font color in wrong way? or other things go wrong? thanks!
colors.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="basic_text_color">#ff932e</color> </resources>
layout
<textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/app_name" android:textsize="20sp" android:textcolor="@colors/basic_text_color" android:layout_gravity="center" android:id="@+id/toolbar_title" />
you have create color resource file if want change textcolor, in question trying set color style.
Comments
Post a Comment