android studio 去掉activity自动生成的Title

几经尝试,发现在eclipse上面可以用的几种方法,在android studio上面行不通。尝试了好多遍,以下方法都来源于eclipse开发

1、以下方法有可能行不通

1android:theme="@android:style/Theme.NoTitleBar" 在文件AndroidManifest.xml中,找到需要全屏或设置成无标题栏的Activity,在该Activity进行如下配置即可。

实现全屏效果: android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 

实现无标题栏: android:theme="@android:style/Theme.NoTitleBar"


2
、在程序中编写代码进行设置,只需在onCreate()方法中加入如下代码即可 

实现全屏效果: 

protected void onCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
}

实现无标题栏:

protected void onCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
}

 

2、下面方法是可行的

在res/values/styles.xml下面新建一个style

<style name="NoTitleStyle" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

然后在项目的清单文件AndroidManifest.xml中将默认的

android:theme="@style/AppTheme"改成android:theme="@style/NoTitleStyle"

 

由于刚刚开始自学android,免得忘了,想写点东西方便以后看,以上方法在android studio行不行都是试出来的,有错误希望指出来,有更简单方法也可以分享一下。


猜你喜欢

转载自blog.csdn.net/qq_25066049/article/details/80172143
今日推荐