Full tutorial is given below. Dear Viewer we are working hard to maintain this website. We doesn't want any think from you. Its just a humble request If you thinks that this posts helps you please share this post with your friends.
hide or show title bar By programatically with java in particular activity
First Method with java
With this code you hide Title Bar
MainActivity.java
package com.usmtip.demoappbyusmtip; import androidx.appcompat.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 setContentView(R.layout.activity_main); } }
With this code you hide Status Bar or you can enable full screen
MainActivity.java
package com.usmtip.demoappbyusmtip; import androidx.appcompat.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); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); //enable full screen setContentView(R.layout.activity_main); } }
you can use both in single activity
With this code you hide Title Bar and Status Bar or you can enable full screen
MainActivity.java
package com.usmtip.demoappbyusmtip; import androidx.appcompat.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); } }
Second Method with App Theme
Go to >> Values
then >> themes or style
and themes.xml
and use this code
Themes.xml
<resources xmlns:tools="http://schemas.android.com/tools"> <!-- Base application theme. --> <style name="Theme.DemoAppByusmtip" parent="Theme.MaterialComponents.DayNight.NoActionBar"> <!-- Primary brand color. --> <item name="colorPrimary">@color/purple_500</item> <item name="colorPrimaryVariant">@color/purple_700</item> <item name="colorOnPrimary">@color/white</item> <!-- Secondary brand color. --> <item name="colorSecondary">@color/teal_200</item> <item name="colorSecondaryVariant">@color/teal_700</item> <item name="colorOnSecondary">@color/black</item> <!-- Status bar color. --> <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item> <!-- Customize your theme here. --> </style> </resources>
Third Method in AndroidManifest.xml
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.usmtip.demoappbyusmtip"> <application android:allowBackup="true" android:icon="@drawable/usmtip" android:label="@string/app_name" android:roundIcon="@drawable/usmtip" android:supportsRtl="true" android:theme="@style/Theme.MaterialComponents.DayNight.NoActionBar"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
Post a Comment