我想为我的一些活动隐藏标题栏。问题是,我应用了一个风格,我所有的活动,因此我不能简单地设置主题@android:style/ theme . notitlebar。
使用NoTitleBar主题作为我的样式的父主题将从我的所有活动中删除标题栏。
我可以在某个地方设置无标题样式的项目吗?
我想为我的一些活动隐藏标题栏。问题是,我应用了一个风格,我所有的活动,因此我不能简单地设置主题@android:style/ theme . notitlebar。
使用NoTitleBar主题作为我的样式的父主题将从我的所有活动中删除标题栏。
我可以在某个地方设置无标题样式的项目吗?
当前回答
在onCreate()方法中执行此操作。
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//set content view AFTER ABOVE sequence (to avoid crash)
this.setContentView(R.layout.your_layout_name_here);
这是指活动。
其他回答
我使用@YaW的解决方案从我的活动中删除标题和通知。但是,标题和通知将在显示对话框时出现。因此,要将此应用到一个对话框,请将该对话框子类化,如下所示:
public class MyDialog extends android.app.Dialog{
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.mydialog);
}
}
我使用的是支持小部件Toolbar v7。 因此,为了能够删除或隐藏标题,我们需要这样写。
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
//Remove¡ing title bar
getSupportActionBar().setDisplayShowTitleEnabled(false);
你可以修改AndroidManifest.xml:
<activity android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
或者使用android:theme="@android:style/ theme . black。NoTitleBar"如果你不需要全屏活动。
注意:如果你之前使用了一个'default'视图,你可能也应该把父类从AppCompatActivity改为Activity。
为你使用的主题添加这两个:
<item name="windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
我正在使用Android Xamarin,这对我来说很有效。
SupportActionBar.Hide();
SetContentView(Resource.Layout.activity_main);