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
I had the same problem, but it solved when i put this on manifest: android:theme="@style/Theme.AppCompat.
<application
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name_test"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat">
...
</application>
In my experiences the problem was the context where I showed my dialog. Inside a button click I instantiate an AlertDialog in this way:
builder = new AlertDialog.Builder(getApplicationContext());
But the context was not correct and caused the error. I've changed it using the application context in this way:
In declare section:
Context mContext;
in the onCreate method
mContext = this;
And finally in the code where I need the AlertDialog:
start_stop = (Button) findViewById(R.id.start_stop);
start_stop.setOnClickListener( new View.OnClickListener()
{
@Override
public void onClick(View v)
{
if (!is_running)
{
builder = new AlertDialog.Builder(mContext);
builder.setMessage("MYTEXT")
.setCancelable(false)
.setPositiveButton("SI", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Task_Started = false;
startTask();
}
})
.setNegativeButton("NO",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
}
This is the solution for me.
Your Activity is extending ActionBarActivity which requires the AppCompat.theme to be applied. Change from ActionBarActivity to Activity or FragmentActivity, it will solve the problem.
If you use no Action bar then :
android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"
You have many solutions to that error.
You should use Activity or FragmentActivity instead of ActionbarActivity or AppCompatActivity
If you want use ActionbarActivity or AppCompatActivity, you should change in styles.xml Theme.Holo.xxxx to Theme.AppCompat.Light (if necessary add to DarkActionbar)
If you don't need advanced attributes about action bar or AppCompat you don't need to use Actionbar or AppCompat.
This solution worked for me.
Design library depends on the Support v4 and AppCompat Support Libraries, so don't use different version for appcompat and design library in gradle.
use
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:design:23.0.0'
instead of
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:design:23.1.0'
go to your styles and put the parent
parent="Theme.AppCompat"
instead of
parent="@android:style/Theme.Holo.Light"