You need to use a Theme.AppCompat theme (or descendant) with this activity.
2017-06-05 17:18
471 查看
今天代码在 builder.show()出报出 You need to use a Theme.AppCompat theme (or descendant) with this activity.
通过看源码分析最后将
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
改为
AlertDialog.Builder builder = new AlertDialog.Builder(activity,R.style.Theme_AppCompat_Light_Dialog_Alert);
解决。
查询网上结果发现
方法1:(此方法问题未解决)
创建的activity时,如果不是那么强烈需要继承自AppCompatActivity,就直接继承Activity。
如将activity继承自AppCompatActivity:
public class MainActivity extends ActionBarActivity
改成activity继承自Activity:
我的Activity继承 android.support.v4.app.FragmentActivity,直接继承Activity后问题依然存在。
方法2:(此方法解决问题)
还是想继承自AppCompatActivity,那么根据提示来使用AppCompat的theme,即将AndroidManifest.xml文件中关于Activity的主题配置改成:
android:theme="@style/Theme.AppCompat.Light.NoActionBar"</code>
完整代码如下:
<activity android:name=".module.view.activity.KuwoMusicPlayActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
这个方法可以解决问题。
通过看源码分析最后将
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
改为
AlertDialog.Builder builder = new AlertDialog.Builder(activity,R.style.Theme_AppCompat_Light_Dialog_Alert);
解决。
查询网上结果发现
方法1:(此方法问题未解决)
创建的activity时,如果不是那么强烈需要继承自AppCompatActivity,就直接继承Activity。
如将activity继承自AppCompatActivity:
public class MainActivity extends ActionBarActivity
改成activity继承自Activity:
我的Activity继承 android.support.v4.app.FragmentActivity,直接继承Activity后问题依然存在。
方法2:(此方法解决问题)
还是想继承自AppCompatActivity,那么根据提示来使用AppCompat的theme,即将AndroidManifest.xml文件中关于Activity的主题配置改成:
android:theme="@style/Theme.AppCompat.Light.NoActionBar"</code>
完整代码如下:
<activity android:name=".module.view.activity.KuwoMusicPlayActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</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解决
- 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解决方法
- 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开发~you need to use a theme.appcompat theme (or descendant) with this activity
- java.lang.IllegalStateException: 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解决方法
- 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.