Multiple implementations of android without the title bar in full screen
- 2020-05-09 19:17:39
- OfStack
1. Realize that all activity in the application are full-screen
Add directly to manifest
2. Realize a single activity full screen
3. Implement a single activity without the title column
1. Change the title: public void setTitle (CharSequence title)
2. Hide the title: requestWindowFeature(Window.FEATURE_NO_TITLE);
3. Hide the title and the top battery and signal bar (full screen) :
4. Customize the title content
In the MainActivity file:
Where, the value obtained by getTitle() is the value above android:label=" @string /titlebar_text"
5. Customize the title layout
res\layout\ custom_title_1.xml contains 1 TextView to display the title. Android can be shown as a title of 1 layout, which is very extensible.
Add directly to manifest
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
2. Realize a single activity full screen
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.TYPE_STATUS_BAR, WindowManager.LayoutParams.TYPE_STATUS_BAR);
3. Implement a single activity without the title column
requestWindowFeature(Window.FEATURE_NO_TITLE);
1. Change the title: public void setTitle (CharSequence title)
2. Hide the title: requestWindowFeature(Window.FEATURE_NO_TITLE);
3. Hide the title and the top battery and signal bar (full screen) :
public void setFullscreen() {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
4. Customize the title content
<activity android:name=".activity.MainActivity" android:screenOrientation="portrait" android:label="@string/titlebar_text"
</actibity> 2 )
In the MainActivity file:
requestWindowFeature(Window.FEATURE_NO_TITLE);
// Set the window to have no title bar
setContentView(R.layout.main);
// Set the value of the title dynamically, getTitle() Is the value of it activity In the statement. android:label The value of the
((TextView) findViewById(R.id.titlebar_text)).setText(getTitle());
Where, the value obtained by getTitle() is the value above android:label=" @string /titlebar_text"
5. Customize the title layout
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Pre-set the window state to allow changes in setContentView Called before, otherwise set the title when throwing runtime error.
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.custom_title);
// The header area can be set to layout , so that there can be a rich way of presentation
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
R.layout.custom_title_1);
}
res\layout\ custom_title_1.xml contains 1 TextView to display the title. Android can be shown as a title of 1 layout, which is very extensible.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/screen"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView android:id="@+id/left_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="@string/custom_title_left" />
</RelativeLayout>