gpt4 book ai didi

android - 如何在 Android SDK 27 中将屏幕方向限制为纵向

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:43:58 27 4
gpt4 key购买 nike

我试过了

android:screenOrientation="portrait"

setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

但它使应用程序崩溃,是否有其他方法可以在 Android 8.0.0+ 中运行?

日志:

FATAL EXCEPTION: main
Process: in.ajtech.finX, PID: 15077
java.lang.RuntimeException: Unable to start activity ComponentInfo{in.ajtech.finX/in.ajtech.finX.CalendarActivity}: java.lang.IllegalStateException: Only fullscreen activities can request orientation
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.IllegalStateException: Only fullscreen activities can request orientation
at android.os.Parcel.readException(Parcel.java:1950)
at android.os.Parcel.readException(Parcel.java:1888)
at android.app.IActivityManager$Stub$Proxy.setRequestedOrientation(IActivityManager.java:5675)
at android.app.Activity.setRequestedOrientation(Activity.java:5739)
at in.ajtech.finX.CalendarActivity.onCreate(CalendarActivity.java:55)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
at android.app.ActivityThread.-wrap11(Unknown Source:0) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
at android.os.Handler.dispatchMessage(Handler.java:105) 
at android.os.Looper.loop(Looper.java:164) 
at android.app.ActivityThread.main(ActivityThread.java:6541) 
at java.lang.reflect.Method.invoke(Native Method) 

最佳答案

错误

阅读Only fullscreen activities can request orientation

Only fullscreen activities can request orientation at android.app.ActivityThread.performLaunchActivity

你应该使用 AppCompatActivity而不是 Activity

让您的 Activity 扩展 AppCompatActivity

Java

public class YourActivity extends AppCompatActivity {
// ...
}

Kotlin

class  YourActivity : AppCompatActivity()

仅供引用

Beginning with Android 3.0 (API level 11), all activities that use the default theme have an ActionBar as an app bar. However, app bar features have gradually been added to the native ActionBar over various Android releases. As a result, the native ActionBar behaves differently depending on what version of the Android system a device may be using. By contrast, the most recent features are added to the support library's version of Toolbar, and they are available on any device that can use the support library.

来自 Setting Up the App Bar .

演示

设置你的风格

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

</style>

关于android - 如何在 Android SDK 27 中将屏幕方向限制为纵向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49124073/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com