Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to hide title bar and status bar in android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 4.10k
    Comment on it

    In many application we need to hide the title bar of Activity/Fragment Activity. For this we need to add following line in onCreate() method before calling setContentView()

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    

    Example:-

    public class MainActivity extends Activity {
    
     @Override
     protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      this.requestWindowFeature(Window.FEATURE_NO_TITLE);
      setContentView(R.layout.activity_main);
     }
    }
    

    To hide status bar from your activity, you can do this by using two ways:-
    1) If you want to hide the status bar from whole application, then you can use the following theme in your manifest file:-

       android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 
    

    Example:-

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />
    
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic&#95;launcher"
        android:label="@string/app&#95;name"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        <activity
            android:name="com.example.MainActivity"
            android:label="@string/app&#95;name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    

    2) If you want to hide a particular activity of your application, then write following line in onCreate() method before calling setContentView():-

     // If the Android version is lower than Jellybean, use this call to hide
            // the status bar.
            if (Build.VERSION.SDK_INT < 16) {
                getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                        WindowManager.LayoutParams.FLAG_FULLSCREEN);
            }
    

    On API level 16 or higher (i.e. Android 4.1 or higher)

    View decorView = getWindow().getDecorView();
    // Hide the status bar.
    int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
    decorView.setSystemUiVisibility(uiOptions);
    // Remember that you should never show the action bar if the
    // status bar is hidden, so hide that too if necessary.
    ActionBar actionBar = getActionBar();
    actionBar.hide();
    

    Hope you like this blog :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: