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
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/
Just Do
new AlertDialog.Builder(this)
Instead of
new AlertDialog.Builder(getApplicationContext())
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>
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.
Make sure you are using an activity context while creating a new Alert Dialog and not an application or base context.
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!