Ví dụ dấu thanh tiêu đề trong android
Trong ví dụ này, chúng tôi sẽ giải thích cách ẩn thanh tiêu đề và cách hiển thị nội dung ở chế độ toàn màn hình.
Gọi phương thức requestWindowFeature(Window.FEATURE_NO_TITLE) của Activity để ẩn thanh tiêu đề. Nhưng nó phải được thêm trước phương thức setContentView.
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE);//will hide the title not the title bar setContentView(R.layout.activity_main); } }
Phương thức setFlags () của lớp Window được sử dụng để hiển thị nội dung ở chế độ toàn màn hình. Bạn cần phải truyền hằng số WindowManager.LayoutParams.FLAG_FULLSCREEN trong phương thức setFlags.
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); //code that displays the content in full screen mode this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//int flag, int mask setContentView(R.layout.activity_main); }
Ví dụ ẩn thanh tiêu đề trong Android
Chúng ta xem toàn bộ mã nguồn ẩn thanh tiêu đề
File: activity_main.xml
<RelativeLayout xmlns:androclass="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> </RelativeLayout>
File: MainActivity.java
Kết quả: Chỉ ẩn thanh tiêu đề
Kết quả: Ẩn thanh tiêu đề và cho phép toàn (full) màn hình
Cập nhật công nghệ từ Youtube tại link: https://www.youtube.com/channel/UCOxeYcvZPGf-mGLYSl_1LuA/videos
Để tham gia khóa học công nghệ truy cập link: http://thuvien.hocviendaotao.com
Mọi hỗ trợ về công nghệ email: dinhanhtuan68@gmail.com