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

前端 未结 30 4119
感动是毒
感动是毒 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:08

    This is when you want a AlertDialog in a Fragment

                AlertDialog.Builder adb = new AlertDialog.Builder(getActivity());
                adb.setTitle("My alert Dialogue \n");
                adb.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
    
                      //some code
    
                } });
                adb.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
    
                     dialog.dismiss();
    
                    } });
                adb.show();
    
    0 讨论(0)
  • 2020-11-21 05:09

    Change the theme of the desired Activity. This works for me:

    <activity
                android:name="HomeActivity"
                android:screenOrientation="landscape"
                android:theme="@style/Theme.AppCompat.Light"
                android:windowSoftInputMode="stateHidden" />
    
    0 讨论(0)
  • 2020-11-21 05:09

    You have came to this because you want to apply Material Design in your theme style in previous sdk versions to 21. ActionBarActivity requires AppThemeso if you also want to prevent your own customization about your AppTheme, only you have to change in your styles.xml (previous to sdk 21) so this way, can inherit for an App Compat theme.

    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
    

    for this:

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    
    0 讨论(0)
  • 2020-11-21 05:10

    This one worked for me:

    <application
               android:allowBackup="true"
               android:icon="@mipmap/ic_launcher"
               android:label="@string/app_name"
               android:theme="@style/AppTheme" >
               <activity
                   android:name=".MainActivity"
                   android:label="@string/app_name"
                   android:theme="@style/Theme.AppCompat.NoActionBar">
    
                   <intent-filter>
                       <action android:name="android.intent.action.MAIN" />
    
                       <category android:name="android.intent.category.LAUNCHER" />
                   </intent-filter>
               </activity>
    </application>
    
    0 讨论(0)
  • 2020-11-21 05:11

    I had such crash on Samsung devices even though the activity did use Theme.AppCompat. The root cause was related to weird optimizations on Samsung side:

    - if one activity of your app has theme not inherited from Theme.AppCompat
    - and it has also `android:launchMode="singleTask"`
    - then all the activities that are launched from it will share the same Theme
    

    My solution was just removing android:launchMode="singleTask"

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

    If you are using the application context, like this:

    final AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
    

    change it to an activity context like this:

    final AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
    
    0 讨论(0)
提交回复
热议问题