Android 隱藏標題欄和全屏示例
在這個示例中,我們將解釋如何隱藏標題欄以及如何在全屏模式下顯示內容。愛掏網 - it200.com
需要調用Activity的 requestWindowFeature(Window.FEATURE_NO_TITLE) 方法來隱藏標題。愛掏網 - it200.com但是,它必須在setContentView方法之前編碼。愛掏網 - it200.com
隱藏Activity標題欄的代碼
使用 getSupportActionBar() 方法來檢索ActionBar類的實例。愛掏網 - it200.com調用ActionBar類的hide()方法隱藏標題欄。愛掏網 - it200.com
requestWindowFeature(Window.FEATURE_NO_TITLE);//will hide the title
getSupportActionBar().hide(); //hide the title bar
啟用全屏模式的代碼
Window類的 setFlags() 方法用于在全屏模式下顯示內容。愛掏網 - it200.com您需要在setFlags方法中傳遞 WindowManager.LayoutParams.FLAG_FULLSCREEN 常量。愛掏網 - it200.com
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); //show the activity in full screen
Android隱藏標題欄和全屏示例
讓我們看一下在安卓中隱藏標題欄的完整代碼。愛掏網 - it200.com
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="first.javatpoint.com.hidetitlebar.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Activity類
package first.javatpoint.com.hidetitlebar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE); //will hide the title
getSupportActionBar().hide(); // hide the title bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN); //enable full screen
setContentView(R.layout.activity_main);
}
}
輸出:僅隱藏標題
輸出:隱藏標題欄并啟用全屏模式
聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。