You need to use a Theme.AppCompat theme (or descendant) with this activity

前端 未结 30 3987
感动是毒
感动是毒 2020-11-21 04:42

Android Studio 0.4.5

Android documentation for creating custom dialog boxes: http://developer.android.com/guide/topics/ui/dialogs.html

If you want a custom d

相关标签:
30条回答
  • 2020-11-21 05:15

    min sdk is 10. ActionBar is available from api level 11. So for 10 you would be using AppCompat from the support library for which you need to use Theme.AppCompat or descendant of the same.

    Use

    android:theme="@style/Theme.AppCompat" >
    

    Or if you dont want action bar at the top

    android:theme="@style/Theme.AppCompat.NoActionBar">
    

    More info @

    http://developer.android.com/guide/topics/ui/actionbar.html

    Edit:

    I might have misread op post.

    Seems op wants a Dialog with a Activity Theme. So as already suggested by Bobbake4 extend Activity instead of ActionBarActivity.

    Also have a look @ Dialog Attributes in the link below

    http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.4_r1/frameworks/base/core/res/res/values/themes.xml/

    0 讨论(0)
  • 2020-11-21 05:15

    Just Do

    new AlertDialog.Builder(this)
    

    Instead of

    new AlertDialog.Builder(getApplicationContext())
    
    0 讨论(0)
  • 2020-11-21 05:15

    In Android manifest just change theme of activity to AppTheme as follow code snippet

    <activity
      android:name=".MainActivity"
      android:label="@string/app_name"
      android:theme="@style/AppTheme">
    </activity>
    
    0 讨论(0)
  • 2020-11-21 05:16

    If you need to extend ActionBarActivity you need on your style.xml:

    <!-- Base application theme. -->
    <style name="AppTheme" parent="AppTheme.Base"/>
    
    <style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    

    If you set as main theme of your application as android:Theme.Material.Light instead of AppTheme.Base then you’ll get an “IllegalStateException:You need to use a Theme.AppCompat theme (or descendant) with this activity” error.

    0 讨论(0)
  • 2020-11-21 05:18

    Make sure you are using an activity context while creating a new Alert Dialog and not an application or base context.

    0 讨论(0)
  • 2020-11-21 05:19

    I was experiencing this problem even though my Theme was an AppCompat Theme and my Activity was an AppCompatActivity (or Activity, as suggested on other's answers). So I cleaned, rebuild and rerun the project.

    (Build -> Clean Project ; Build -> Rebuild Project ; Run -> Run)

    It may seem dumb, but now it works great!

    Just hope it helps!

    0 讨论(0)
提交回复
热议问题