我试图实现颜色状态列表资源在我的Android应用程序,以下Android开发者指南颜色状态列表资源| Android开发人员。因此,我在目录中创建了两个资源文件button_text.xml和button_background.xml,res/color/并在@color/button_text和中@color/button_background分别引用了它们activity_main.xml。这是布局代码:
<Button
android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:layout_marginTop="150dp"
android:layout_gravity="center"
android:textColor="@color/button_text"
android:background="@color/button_background"/>
Run Code Online (Sandbox Code Playgroud)
在运行该应用程序时,我Resources Not Found Exception在日志中得到如下所示:
Process: com.example.myanimation, PID: 29254
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myanimation/com.example.myanimation.MainActivity}: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class Button
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2659)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2724)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6123)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at …Run Code Online (Sandbox Code Playgroud)