解决You need to use a Theme.AppCompat theme (or descendant) with this activity.

解决

You need to use a Theme.AppCompat theme (or descendant) with this activity.

解决方法
方法1:
创建的activity时,如果不是那么强烈需要继承自AppCompatActivity,就直接继承Activity。
如将activity继承自AppCompatActivity:

public class MainActivity extends ActionBarActivity

改成activity继承自Activity:

public class MainActivity extends Activity

方法2:
还是想继承自AppCompatActivity,那么根据提示来使用AppCompat的theme,即将AndroidManifest.xml文件中关于Activity的主题配置改成:

android:theme="@style/Theme.AppCompat.Light.NoActionBar"

设置透明Activity:
在你的AndroidManifest里的Activity标签里配置透明主题:

android:theme=”@android:style/Theme.Translucent”
android:theme=”@android:style/Theme.Translucent.NoTitleBar”
android:theme=”@android:style/Theme.Translucent.NoTitleBar.Fullscreen”

第一种保留标题和状态栏,其他为透明色
第二种保留状态栏,其他为透明色
第三种全屏透明

以上三种选一种即可。

一般情况下当一个Activity被其他Activity覆盖时,被覆盖的Activity都会调用onStop()方法,但是有两种情况除外,一个是上层Activity是Dialog风格时,另外一个是上层Activity是透明时;这两种情况只会调用onPause()方法,但不会调用onStop方法.

一个应用采用了多进程方案,运行在不同进程的组件不会相互影响,比如崩溃。通过在Manifest指定android:process=":test"即可让Activity等运行在packagename:test进程中。假设Activity A 启动了Activity B,Activity B运行在packagename:test进程,且Activity B设置了windowIsTranslucent 为 true,那么当Activity B崩溃后,整个应用都会退出,包括Activity A,并弹出系统的崩溃提示框。如果Activity B没有设置windowIsTranslucent 为 true,Activity B崩溃不会影响 Activity A。

  • 24
    点赞
  • 34
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.hjschoolhelper210301201_1, PID: 2778 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.hjschoolhelper210301201_1/com.example.hjschoolhelper210301201_1.LoginMainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3645) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3782) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7872) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:846) at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:809) at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696) at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195) at com.example.hjschoolhelper210301201_1.LoginMainActivity.onCreate(LoginMainActivity.java:26) at android.app.Activity.performCreate(Activity.java:8305) at android.app.Activity.performCreate(Activity.java:8284) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1417) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3626) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3782)  at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101)  at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307)  at android.os.Handler.dispatchMessage(Handler.java:106)  at android.os.Looper.loopOnce(Looper.java:201)  at android.os.Looper.loop(Looper.java:288)  at android.app.ActivityThread.main(ActivityThread.java:7872)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) 
最新发布
05-23
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值