I am developing an Android app. In my app, I need to start activity as dialog. I found a way to do it by setting dialog theme in manifest. But when I start activity, it is giving me error.
This is how I configure in manifest
<activity android:name=".ReplyActivity"
android:label="Reply"
android:theme="@android:style/Theme.Holo.Dialog">
<action android:name="com.blog.waiyanhein.mmfashion.SettingsActivity"/>
<category android:name="android.intent.category.DEFAULT"/>
</activity>
This is how I start activity in adapter
private void openReplyActivity(int position)
{
Intent intent = new Intent(context, ReplyActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(ReplyActivity.NOTI_ID_FIELD,values.get(position).getId());
intent.putExtra(ReplyActivity.REPLY_TO_FIELD,values.get(position).getUsername());
context.startActivity(intent);
}
This is XML layout for dialog activity
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/reply_tv_to_title"
android:text="Reply to"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/reply_tv_reply_to"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/reply_tf_message"
android:layout_width="match_parent"
android:layout_height="120dp" />
<android.support.v7.widget.AppCompatButton
android:layout_below="@+id/reply_tf_message"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:background="@color/colorAccent"
android:textColor="@color/white"
android:text="Reply"
android:id="@+id/reply_btn_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</LinearLayout>
This is the error I get in Logcat
06-15 07:17:08.092 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa4b65648)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: FATAL EXCEPTION: main
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.blog.waiyanhein.mmfashion.mmfashion/com.blog.waiyanhein.mmfashion.mmfashion.ReplyActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at android.os.Looper.loop(Looper.java:137)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5103)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:525)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:310)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:279)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:253)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at com.blog.waiyanhein.mmfashion.mmfashion.ReplyActivity.onCreate(ReplyActivity.java:25)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at android.app.Activity.performCreate(Activity.java:5133)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at android.os.Looper.loop(Looper.java:137)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5103)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:525)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
06-15 07:17:08.096 20542-20542/com.blog.waiyanhein.mmfashion.mmfashion E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
I set support library in Gradle like this
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
What is wrong with my code? Why can I not start activity as dialog with code?