我遇到了一个特别奇怪的崩溃,长时间点击EditText,里面有一些文字(否则工作正常)。这是系统地发生的。
这是stacktrace:
android.content.res.Resources$NotFoundException: Resource is not a ColorStateList (color or path): TypedValue{t=0x2/d=0x1010036 a=3}
at android.content.res.Resources.loadColorStateList(Resources.java:3532)
at android.content.res.TypedArray.getColorStateList(TypedArray.java:343)
at android.widget.TextView.setTextAppearance(TextView.java:3149)
at android.support.v7.widget.AppCompatTextView.setTextAppearance(AppCompatTextView.java:56)
at android.support.v7.internal.widget.ActionBarContextView.initTitle(ActionBarContextView.java:139)
at android.support.v7.internal.widget.ActionBarContextView.setTitle(ActionBarContextView.java:115)
at android.support.v7.internal.view.StandaloneActionMode.setTitle(StandaloneActionMode.java:60)
at android.support.v7.internal.view.SupportActionModeWrapper.setTitle(SupportActionModeWrapper.java:63)
at android.widget.Editor$SelectionActionModeCallback.onCreateActionMode(Editor.java:3268)
at com.android.internal.policy.impl.PhoneWindow$DecorView$ActionModeCallbackWrapper.onCreateActionMode(PhoneWindow.java:3039)
at android.support.v7.internal.view.SupportActionModeWrapper$CallbackWrapper.onCreateActionMode(SupportActionModeWrapper.java:155)
at android.support.v7.app.AppCompatDelegateImplV7$ActionModeCallbackWrapperV7.onCreateActionMode(AppCompatDelegateImplV7.java:1644)
at android.support.v7.app.AppCompatDelegateImplV7.startSupportActionModeFromWindow(AppCompatDelegateImplV7.java:748)
at android.support.v7.app.AppCompatDelegateImplV7.startSupportActionMode(AppCompatDelegateImplV7.java:642)
at android.support.v7.app.AppCompatDelegateImplV14$AppCompatWindowCallbackV14.startAsSupportActionMode(AppCompatDelegateImplV14.java:74)
at android.support.v7.app.AppCompatDelegateImplV14$AppCompatWindowCallbackV14.onWindowStartingActionMode(AppCompatDelegateImplV14.java:58)
at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionMode(PhoneWindow.java:2651)
at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionModeForChild(PhoneWindow.java:2638)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:675)
at android.view.View.startActionMode(View.java:4756)
at android.widget.Editor.startSelectionActionMode(Editor.java:1831)
at android.widget.Editor.performLongClick(Editor.java:1060)
at android.widget.TextView.performLongClick(TextView.java:10149)
at android.view.View$CheckForLongPress.run(View.java:19433)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5653)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
at dalvik.system.NativeStart.main(Native Method)
我在SO上看了几篇帖子,但到目前为止还没有运气。我还必须提到这种情况发生在三星Galaxy Tab 3 API 19上,因为它似乎已经标记了issues但是票证显示为固定。
以下是一些代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_login">
<Button
android:id="@+id/mServerUrlButton"
style="@style/OkButton"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="100dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="100dp"
android:layout_marginStart="30dp"
android:layout_marginTop="90dp"/>
<EditText
android:id="@+id/mServerUrlEditText"
style="@style/LoginField"
android:layout_width="500dp"
android:layout_marginTop="90dp"
android:layout_toLeftOf="@id/mServerUrlButton"
android:layout_toStartOf="@id/mServerUrlButton"
android:hint="@string/server_url_placeholder"
android:inputType="textUri"/>
</RelativeLayout>
和styles.xml:
<style name="AppTheme" parent="AppTheme.Base"/>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/green</item>
<item name="colorPrimaryDark">@color/green</item>
<item name="colorAccent">@color/green</item>
<item name="colorControlNormal">@color/black</item>
<item name="colorControlActivated">?attr/colorControlNormal</item>
<item name="colorControlHighlight">?attr/colorControlNormal</item>
<item name="android:textColorPrimary">?attr/colorControlNormal</item>
<item name="android:textColorSecondary">?attr/colorControlNormal</item>
<item name="android:windowContentOverlay">@null</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:fitsSystemWindows">true</item>
</style>
<style name="OkButton" parent="@android:style/Widget.Button">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">@dimen/confirm_button_height</item>
<item name="android:background">@drawable/bg_login_button</item>
<item name="android:text">@string/ok_button</item>
<item name="android:textColor">@color/white</item>
<item name="android:textSize">20sp</item>
<item name="android:paddingLeft">16dp</item>
<item name="android:paddingRight">16dp</item>
</style>
<style name="Field" parent="@android:style/Widget.EditText">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">match_parent</item>
<item name="android:background">@drawable/bg_login_field</item>
<item name="android:textColorHint">@color/black</item>
<item name="android:textSize">15sp</item>
<item name="android:padding">10dp</item>
<item name="android:gravity">top</item>
<item name="android:singleLine">true</item>
</style>
<style name="LoginField" parent="Field">
<item name="android:layout_width">@dimen/login_field_width</item>
<item name="android:layout_height">@dimen/login_field_height</item>
<item name="android:gravity">center_vertical</item>
</style>
这不是来自我的提示颜色或背景可绘制,因为我已经尝试逐个禁用它们以查看它失败的位置。即使没有任何自定义(只需要宽度和高度),它仍然会崩溃。
仍然是我的colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="white">#FFFFFF</color>
<color name="black">#000000</color>
<color name="green">#015b27</color>
<color name="pink">#a10453</color>
<color name="gray">#707070</color>
<color name="light_gray">#B6B6B6</color>
<color name="light_green">#8AC97A</color>
<color name="light_pink">#FF84C2</color>
<color name="white_alpha">#DDFFFFFF</color>
<color name="black_alpha">#80000000</color>
</resources>
我的绘画:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:radius="10dp" />
<solid android:color="@color/white" />
<stroke android:width="1dp" android:color="@color/black" />
</shape>
任何帮助将不胜感激! :)
答案 0 :(得分:1)
好的,所以我终于找到了罪魁祸首......似乎在任何 android:textColor [*] 属性上调用?attr / colorControlNormal 无法找到在styles.xml中的颜色引用。我必须首先定义文本主色,然后使用“android”命名空间从主要用户定义辅助颜色。
所以我的AppTheme.Base现在看起来像:
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/green</item>
<item name="colorPrimaryDark">@color/green</item>
<item name="colorAccent">@color/green</item>
<item name="colorControlNormal">@color/black</item>
<item name="colorControlActivated">?attr/colorControlNormal</item>
<item name="colorControlHighlight">?attr/colorControlNormal</item>
<item name="android:textColorPrimary">@color/black</item>
<item name="android:textColorSecondary">?android:attr/textColorPrimary</item>
<item name="android:windowContentOverlay">@null</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:fitsSystemWindows">true</item>
</style>