Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
77 views
in Technique[技术] by (71.8m points)

android - How to make an application ignore screen orientation change?

Is there a way to make an application completely ignore a screen orientation change?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It is possible, quite easily, to override the default behavior and forbid a screen orientation change when the keyboard is open/closed.

Modifying the manifest

Open the manifest, switch to the Application tab and select the desired Activity you wish to override for the orientation change behavior.

  1. Within Attributes you need to change two fields: Screen orientation: select either portrait or landscape - whichever is desired. This will be the default layout.

  2. Select events for Config changes you wish to override: In this case these are keyboardHidden and orientation.

Modifying the Activity implementation

Now you need to override a single function within desired Activity.

Just add the function below to your Activity's class.

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
}

This is the default implementation if using the Source->Override/Implement Methods menu option.

That's it! Now your orientation will always be kept.

Remember that this setting is per Activity - so you need to repeat this step for each Activity you wish to forbid the orientation change!

(Based on SDK 1.1)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...