问题描述
我有一个使用最新版本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:
它也显示蓝色信息:
为什么呢?我在做什么错了?
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"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!