Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove title bar from the android activity?

Can someone please help me with the issue.I want my activity as full screen and want to remove title from the screen.I have tried several ways but not able to remove it.

Activity Code :

public class welcomepage extends Activity {     private Button btn;     EditText userName,passWord;     DatabaseHandler dbHandler;     Context ctx =this;     @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         //Remove title bar         this.requestWindowFeature(Window.FEATURE_NO_TITLE);         setContentView(R.layout.activity_welcomepage);    } } 

And Activity.xml

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout    xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     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"     android:background="@drawable/pic1"     app:layout_behavior="@string/appbar_scrolling_view_behavior"     tools:context="com.edkul.vimal.edkul.welcomepage">  </RelativeLayout> 

I want to remove the title bar displayed in blue color .Please find the image for the reference :

enter image description here

AndroidManifest.xml

<application         android:minSdkVersion="3"         android:allowBackup="true"         android:icon="@mipmap/ic_launcher"         android:label="@string/app_name"         android:supportsRtl="true"         android:theme="@style/Theme.AppCompat.NoActionBar">         <activity             android:name=".welcomepage"             android:label="@string/app_name"             android:theme="@style/Theme.AppCompat.NoActionBar">             <intent-filter>                 <action android:name="android.intent.action.MAIN" />                 <category    android:name="android.intent.category.LAUNCHER" />             </intent-filter>         </activity> </application> 
like image 946
vimal mishra Avatar asked Mar 26 '16 14:03

vimal mishra


People also ask

How do I remove the title bar Kotlin?

Another way for removing the title specifically from an activity is by using a getSupportActionBar(). hide() method. Inside the activity's kotlin file, we need to invoke getSupportActionBar(). hide() method.


2 Answers

you just add this style in your style.xml file which is in your values folder

<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.DarkActionBar">     <item name="windowActionBar">false</item>     <item name="windowNoTitle">true</item>     <item name="android:windowFullscreen">true</item> </style> 

After that set this style to your activity class in your AndroidManifest.xml file

android:theme="@style/AppTheme.NoActionBar" 

Edit:- If you are going with programmatic way to hide ActionBar then use below code in your activity onCreate() method.

if(getSupportedActionbar()!=null)          this.getSupportedActionBar().hide(); 

and if you want to hide ActionBar from Fragment then

getActivity().getSupportedActionBar().hide(); 

AppCompat v7:- Use following theme in your Activities where you don't want actiobBar Theme.AppComat.NoActionBar or Theme.AppCompat.Light.NoActionBar or if you want to hide in whole app then set this theme in your <application... /> in your AndroidManifest.

In Kotlin:

add this line of code in your onCreate() method or you can use above theme.

supportActionBar?.hide() 

i hope this will help you more.

like image 195
Shailesh Avatar answered Sep 19 '22 20:09

Shailesh


Try this:

this.getSupportActionBar().hide();

@Override protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);      try     {         this.getSupportActionBar().hide();     }     catch (NullPointerException e){}      setContentView(R.layout.activity_main); } 
like image 44
Christer Avatar answered Sep 21 '22 20:09

Christer