Android Hide Title Bar and Example - مدونة أون لاين كلاو | Online Claw

إعلان فوق المشاركات

Android Hide Title Bar and Example

Android Hide Title Bar and Example

شارك المقالة



Android Hide Title Bar and Example

In this example, we are going to explain how to hide the title bar and how to display content in full screen mode.
The requestWindowFeature(Window.FEATURE_NO_TITLE) method of Activity must be called to hide the title. But, it must be coded before the setContentView method.
  1.     @Override  
  2.     protected void onCreate(Bundle savedInstanceState) {  
  3.         super.onCreate(savedInstanceState);  
  4.           
  5.         requestWindowFeature(Window.FEATURE_NO_TITLE);//will hide the title not the title bar  
  6.           
  7.         setContentView(R.layout.activity_main);  
  8.         
  9.     }  
  10. }  
The setFlags() method of Window class is used to display content in full screen mode. You need to pass theWindowManager.LayoutParams.FLAG_FULLSCREEN constant in the setFlags method.
  1. @Override  
  2. protected void onCreate(Bundle savedInstanceState) {  
  3.     super.onCreate(savedInstanceState);  
  4.       
  5.     requestWindowFeature(Window.FEATURE_NO_TITLE);  
  6.     //code that displays the content in full screen mode  
  7.     this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  
  8.                 WindowManager.LayoutParams.FLAG_FULLSCREEN);//int flag, int mask  
  9.       
  10.     setContentView(R.layout.activity_main);  
  11.     
  12. }  

Android Hide Title Bar Example

Let's see the full code to hide the title bar in android.

activity_main.xml

File: activity_main.xml
  1. <RelativeLayout xmlns:androclass="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:paddingBottom="@dimen/activity_vertical_margin"  
  6.     android:paddingLeft="@dimen/activity_horizontal_margin"  
  7.     android:paddingRight="@dimen/activity_horizontal_margin"  
  8.     android:paddingTop="@dimen/activity_vertical_margin"  
  9.     tools:context=".MainActivity" >  
  10.   
  11.     <TextView  
  12.         android:layout_width="wrap_content"  
  13.         android:layout_height="wrap_content"  
  14.         android:text="@string/hello_world" />  
  15.   
  16. </RelativeLayout>  

Activity class

File: MainActivity.java
  1. package com.javatpoint.hidetitle;  
  2.   
  3. import android.os.Bundle;  
  4. import android.app.Activity;  
  5. import android.view.Menu;  
  6. import android.view.Window;  
  7. import android.view.WindowManager;  
  8.   
  9. public class MainActivity extends Activity {  
  10.   
  11.     @Override  
  12.     protected void onCreate(Bundle savedInstanceState) {  
  13.         super.onCreate(savedInstanceState);  
  14.           
  15.         requestWindowFeature(Window.FEATURE_NO_TITLE);  
  16.        
  17.       /*this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
  18.                   WindowManager.LayoutParams.FLAG_FULLSCREEN);//int flag, int mask 
  19.       */  
  20.         setContentView(R.layout.activity_main);  
  21.           
  22.     }  
  23.   
  24.   
  25. }  


Output: Hiding the Title Only

android hide title bar example output 1

Output: Hiding the TitleBar and enabling FullScreen

android hide title bar example output 2

ليست هناك تعليقات:

إرسال تعليق

إعلان اسفل المشاركات

كن على أتصال

أكثر من 600,000+ متابع على مواقع التواصل الإجتماعي كن على إطلاع دائم معهم

أحدث الاخبار

نموذج الاتصال

الاسم

بريد إلكتروني *

رسالة *

عدد الزوار حالياً

Flag Counter