You need to use a Theme.AppCompat theme (or descendant) with this activity.
2017-11-05 11:15
435 查看
经常在AndroidManifast文件中对一个activity设置一个theme后,会报You need to use a Theme.AppCompat theme (or descendant) with this activity.的错误。我在设置一个页面为透明状态的时候出现这样错误。出现这样的错误的时候经常会是这样的情况:情况1:AndroidManifast.xml
<activity android:name=".view.activity.main.GuideActivity" android:theme="@android:style/Theme.Translucent"android:windowSoftInputMode="stateVisible|adjustResize" />
情况2:
AndroidManifast.xml
<activityandroid:name=".view.activity.main.GuideActivity"android:theme="@style/myTransparent"android:windowSoftInputMode="stateVisible|adjustResize" />
styles:
<!--全透明--><style name="myTransparent" parent="@android:style/Theme.Translucent.NoTitleBar"><item name="android:windowBackground">@color/none_color</item><item name="android:windowAnimationStyle">@null</item><item name="android:windowIsTranslucent">true</item><item name="android:windowNoTitle">true</item> <!-- 无标题 --><item name="android:windowContentOverlay">@null</item></style>
出现这样的情况是因为我们的GuideActivity继承了v7包下的Activity(如AppCompatActivity、ActionBarActivity),所以我们在设置Activity的主题
的时候也要使用v7包下的。所以在我的GuideActivity继承了AppCompatActivity的时候,我要给这个页面设置成透明状态的时候,做法应该是:
AndroidManifast.xml
<activityandroid:name=".view.activity.main.GuideActivity"android:theme="@style/myTransparent"android:windowSoftInputMode="stateVisible|adjustResize" />
styles:
<!--全透明--><style name="myTransparent" parent="Theme.AppCompat.Light.NoActionBar"><item name="android:windowBackground">@color/none_color</item><item name="android:windowAnimationStyle">@null</item><item name="android:windowIsTranslucent">true</item><item name="android:windowNoTitle">true</item> <!-- 无标题 --><item name="android:windowContentOverlay">@null</item></style>
相关文章推荐
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- Android--You need to use a Theme.AppCompat theme (or descendant) with this activity解决方案
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- 使用AlertDialog报错 You need to use a Theme.AppCompat theme (or descendant) with this activity.之解决
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- You need to use a Theme.AppCompat theme (or descendant) with this activity.
- 【我的Android进阶之旅】解决bug:You need to use a Theme.AppCompat theme (or descendant) with this activity.
- 异常IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
- Android问题集锦之二十八:You need to use a Theme.AppCompat theme (or descendant) with this activity.
- You need to use a Theme.AppCompat theme (or descendant) with this activity.
- You need to use a Theme.AppCompat theme (or descendant) with this activity.
- 解决Android: You need to use a Theme.AppCompat theme (or descendant) with this activity.
- Android Studio: You need to use a Theme.AppCompat theme (or descendant) with this activity.
- 对话框报错 You need to use a Theme.AppCompat theme (or descendant) with this activity.
- You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- You need to use a Theme.AppCompat theme (or descendant) with this activity.异常处理其一
- 【Android】You need to use a Theme.AppCompat theme (or descendant) with this activity解决方法
- You need to use a Theme.AppCompat theme (or descendant) with this activity
- Android Studio: You need to use a Theme.AppCompat theme (or descendant) with this activity.
- 关于“you need to use a theme.appcompat theme (or descendant) with this activity”错误