仅纵向电话,平板电脑所有方向:无法解析符号"ActivityInfo" [英] Phone only portrait, tablet all orientations: Cannot resolve symbol 'ActivityInfo'

查看:135
本文介绍了仅纵向电话,平板电脑所有方向:无法解析符号"ActivityInfo"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用最新版本Android Studio构建的Android应用.

I have an Android app build with the newest version of Android Studio.

我想只允许在手机上使用纵向模式,而在平板电脑上只能使用所有方向.

I want to allow only portrait mode on phone but all orientations on tablets.

我遵循了答案,还遵循了

I followed this answer and also this post.

我按照描述做了一切.

然后我打开文件 activity/MainActivity.java .

我寻找了以下代码行: public void onCreate(Bundle savedInstanceState){

I looked for this line of code: public void onCreate(Bundle savedInstanceState) {

然后我在此代码下方添加了以下代码:

Then I added the following code below this code:

if(getResources().getBoolean(R.bool.portrait_only)) {
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

这是一个小片段:

@Override
public void onCreate(Bundle savedInstanceState) {

    if(getResources().getBoolean(R.bool.portrait_only)) {
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

ActivityInfo 为红色,并显示以下错误消息:

ActivityInfo has a red color with the following error message:

无法解析符号'ActivityInfo'

Cannot resolve symbol 'ActivityInfo'

它也显示蓝色信息:

android.content.pm.ActivityInfo?⌥⏎

android.content.pm.ActivityInfo? ⌥⏎

为什么呢?我在做什么错了?

Why that? What am I doing wrong?

推荐答案

您需要在包名称下方的文件顶部添加以下行,以导入ActivityInfo: import android.content.pm.ActivityInfo;

You need to add the following line at the top of your file below package name to import ActivityInfo: import android.content.pm.ActivityInfo;

这篇关于仅纵向电话,平板电脑所有方向:无法解析符号"ActivityInfo"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆