How to hide the title bar through code in android

2019-01-24 14:08发布

I want to hide the title bar using code for some of my activities.

I have used the following code

this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                          WindowManager.LayoutParams.FLAG_FULLSCREEN);

the second line is working for full screen but it shows the application title. Lets say for my splash screen i want to hide my title. The 1st line of code crashes my application. Please help me if we can do it using code.

thanks.

5条回答
Anthone
2楼-- · 2019-01-24 14:22

Make sure you are calling setContentView after these 2 lines

查看更多
再贱就再见
3楼-- · 2019-01-24 14:25
this.requestWindowFeature(Window.FEATURE_NO_TITLE);

You should call this before your setContentView() method, did you do that?

You could always do it in your manifest by adding android:theme="@android:style/Theme.NoTitleBar" to your activity

查看更多
做自己的国王
4楼-- · 2019-01-24 14:29

If you are using API 11 and above

ActionBar actionBar = getActionBar();
actionBar.hide(); // slides out
actionBar.show(); // slides in
查看更多
相关推荐>>
5楼-- · 2019-01-24 14:32

To hide title bar and status bar:

try
   {((View)act.findViewById(android.R.id.title).getParent()).setVisibility(View.GONE);
   }
catch (Exception e) {}
act.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
act.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
view.requestLayout();

To show title bar and status bar:

try
   {((View)act.findViewById(android.R.id.title).getParent()).setVisibility(View.VISIBLE);
   }
catch (Exception e) {}
act.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
act.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
view.requestLayout();
查看更多
三岁会撩人
6楼-- · 2019-01-24 14:40

for remove Application Titlebar then add this line

requestWindowFeature(Window.FEATURE_NO_TITLE);

before setContentView(R.layout.main);

查看更多
登录 后发表回答