Ich entwickle eine Android App. In meiner App muss ich die Aktivität als Dialog starten. Ich habe einen Weg gefunden, dies zu tun, indem ich das Dialogthema im Manifest einstelle. Aber wenn ich die Aktivität starte, gibt es mir einen Fehler. Bitte sehen Sie mein Szenario unten.Ich kann keine Aktivität als Dialog in Android öffnen
konfigurierenDies ist, wie ich in einem offenkundigen
<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>
Dies ist, wie ich Aktivität 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);
}
Dies ist xml-Layout für Dialog Aktivität starten
<?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>
Dies ist der Fehler, den ich
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 Support-Bibliothek in grandle gesetzt wie diese
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
So in Logcat Sie bitte, was ist wron g mit meinem Code? Warum kann ich die Aktivität nicht als Dialog mit Code starten?
* Dies ist der Fehler, den ich in Logcat * erhalten '... Verursacht durch: java.lang.IllegalStateException: Sie benötigen ein Theme.AppCompat Thema (oder Nachkommen) mit dieser Aktivität verwenden ...'. .. scheint, als ob Sie Probleme beim Lesen haben – Selvin
Mögliches Duplikat von [Sie müssen ein Theme.AppCompat-Thema (oder einen Nachkommen) mit dieser Aktivität verwenden] (http://stackoverflow.com/questions/21814825/you-need-to- use-a-theme-appcompat-theme-oder-democendant-with-this-activity) – Selvin