猿问

实现点击一个界面上的按钮弹出另一个界面,另一个界面以对话框形式显示

<activity android:name=".FirstActivity">
   <intent-filter>
       <action android:name="android.intent.action.MAIN" />

       <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
</activity>

<activity
   android:name=".SecondActivity"
   android:theme="@android:style/Theme.DeviceDefault.Dialog"
   />


btn1.setOnClickListener(new View.OnClickListener(){
   @Override
   public void onClick(View view) {
       Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
       FirstActivity.this.startActivity(intent);
   }
});

报错:

07-31 16:38:59.871 7159-7159/com.example.form.myformcomponent I/locat: 执行了--------------onCreate()方法
07-31 16:38:59.991 7159-7159/com.example.form.myformcomponent I/locat: 执行了--------------onStart()方法
07-31 16:39:00.001 7159-7159/com.example.form.myformcomponent I/locat: 执行了--------------onResume()方法
07-31 16:39:00.131 7159-7218/com.example.form.myformcomponent I/OpenGLRenderer: Initialized EGL, version 1.4
07-31 16:39:00.151 7159-7159/com.example.form.myformcomponent W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
07-31 16:39:03.921 7159-7159/com.example.form.myformcomponent I/locat: 执行了--------------onPause()方法
07-31 16:39:03.931 7159-7159/com.example.form.myformcomponent E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.form.myformcomponent, PID: 7159
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.form.myformcomponent/com.example.form.myformcomponent.SecondActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2519)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2586)
at android.app.ActivityThread.access$900(ActivityThread.java:163)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1462)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5574)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:962)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:356)
at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:325)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:286)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at com.example.form.myformcomponent.SecondActivity.onCreate(SecondActivity.java:12)
at android.app.Activity.performCreate(Activity.java:6084)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1120)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2472)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2586)
at android.app.ActivityThread.access$900(ActivityThread.java:163)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1462)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5574)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:962)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:757)
07-31 16:39:03.961 7159-7159/com.example.form.myformcomponent I/Process: Sending signal. PID: 7159 SIG: 9



慕桂英2234914
浏览 4207回答 1
1回答

蜂之谷

<activity    android:name=".SecondActivity"    android:theme="@style/Theme.AppCompat.Dialog"    />错误不是提示了吗,改下主题就好了
随时随地看视频慕课网APP

相关分类

Android
我要回答