开发者

Android: how to disable FEATURE_NO_TITLE

开发者 https://www.devze.com 2023-02-07 22:32 出处:网络
I want my Android application to behave like below. 1) Portrait mode: With title bar 2) Landscape mode: Without title bar (because of height limitation)

I want my Android application to behave like below. 1) Portrait mode: With title bar 2) Landscape mode: Without title bar (because of height limitation)

I know I can realize 1) using requestWindowFeature(Window.FEATURE_NO_TITLE), but how can I dynamically change from 1) to 2) when I rotate开发者_如何学C my phone?


When the phone is rotated, your activity is shut down and recreated. Inside onCreate, you can grab an instance of Display (using getWindowManager().getDefaultDisplay()) and query its width, height, and/or rotation to decide if you want a title feature, all before setting the content view.


This answer suggests you can't change the feature during the lifecycle of the activity (as happens when the orientation changes), so they recommend implementing your own title (jump to the "::Edit::" part):

Hiding Title in a Fullscreen mode?

::Edit::

Well if you are trying to dynamically show and hide it during the lifetime of the activity I am not sure if you can do that with the official Window Title due to the note that has been mentioned about window features needing to be set before setContentView() is called.

One thing that you could do is implement your own title bar and dynamically show and hide that... I put together this example that should set you o nthe right track

Since when you change orientation, your app goes through a set of lifecycle changes, you have an opportunity in onCreate to show or hide your title.

http://stuffthathappens.com/blog/2008/11/26/android-lifecycle-triggers-part-2/

Android: how to disable FEATURE_NO_TITLE

Or you specify a different layout altogether for landscape mode:

http://developer.android.com/resources/tutorials/hello-world.html

Landscape layout

When you want a different design for landscape, put your layout XML file inside /res/layout-land. Android will automatically look here when the layout changes. Without this special landscape layout defined, Android will stretch the default layout.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号