Cover Image for Hide Title Bar in Android
98 views

Hide Title Bar in Android

To hide the title bar (also known as the action bar) in an Android app, you can use one of two approaches, depending on your specific requirements:

1. Hide Title Bar Programmatically:

If you want to hide the title bar for a specific activity programmatically, you can do so in the onCreate() method of your activity by calling requestWindowFeature(Window.FEATURE_NO_TITLE) before setContentView():

Java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Hide the title bar
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.activity_main);
}

2. Set in the AndroidManifest.xml:

If you want to hide the title bar for the entire application, you can set a theme in the AndroidManifest.xml file.

  1. Create a Theme: Open the styles.xml file located in the res/values folder. If it doesn’t exist, create it. Define a custom theme that inherits from a parent theme, but overrides the action bar style. Add the following style to your styles.xml:
XML
 <resources>
     <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
         <!-- Customize other attributes if needed -->
     </style>
 </resources>

In this example, the theme AppTheme inherits from Theme.AppCompat.Light.NoActionBar, which means it uses a light color scheme and does not include the action bar.

  1. Apply the Theme in AndroidManifest.xml: Open the AndroidManifest.xml file and locate the <application> element. Add the android:theme attribute and set it to the theme you created:
XML
 <application
     android:theme="@style/AppTheme"
     ...
 >
 ...
 </application>

This will apply the AppTheme to your entire application, which means the title bar will be hidden for all activities.

Remember to customize the theme according to your application’s requirements. You can adjust colors, styles, and other attributes as needed.

Keep in mind that if you’re using a different parent theme (other than Theme.AppCompat.Light.NoActionBar), you may need to adjust the styling accordingly.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS