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
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();
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" />
You have came to this because you want to apply Material Design in your theme style in previous sdk versions to 21. ActionBarActivity
requires AppTheme
so 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">
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>
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"
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);