The main cause of this problem seems to be a missing style/theme in the AppCompat library, or a bug in the library. It happens when using either AppCompatEditText or AppCompatAutoCompleteTextView and a WebView is also added to the layout (AdMob ads are WebViews). It happens on several versions of AppCompat, like 23, 24, 25, 26.
It can be seen more clearly in a useful demo app that someone made on Github:
- Clone the repo and open in Android Studio v2.3 or higher.
- Android Studio should prompt to update the gradle dependencies and buildToolsVersion in this project, something like this:
build.gradle:
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
...
}
app/build.gradle:
buildToolsVersion '25.0.0'
gradle-wrapper.properties:
distributionUrl=https://services.gradle.org/distributions/gradle-3.3-all.zip
- Update the dependencies then build the project. Run the app on Android 7 emulator or device, with a stock Android keyboard. Set the system language to English.
- On the input field, type the letters 'tttf' on the Android keyboard. Then press space. The word should be underlined as misspelled.
- Now click one of the letters (not long-press) to try to move the cursor. It should crash the app - like this:
The solution (from here) is to explicitly add both "colorAccent"
and "android:colorAccent"
in your main AppTheme, in styles.xml:
<style name="AppTheme" parent="Theme.AppCompat">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:colorAccent" tools:targetApi="lollipop">@color/colorAccent</item>
</style>
or
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:colorAccent" tools:targetApi="lollipop">@color/colorAccent</item>
</style>
This will now work to allow the stock spelling suggestions popup to appear, and no more crashing.
Similar reports or duplicates:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…