android隐藏标题栏个人心得,欢迎指正

1.依赖android-support-v7-appcompat

 1.1 getSupportActionBar().hide();必须放在setContentView之前,这种只能解决单个activity的问题。

public class MainActivity extends AppCompatActivity{

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//去除标题栏
		getSupportActionBar().hide();
		setContentView(R.layout.activity_main);

1.2     把parent改变一下,另外再加一个item“windowNoTitle”,application节点下的them不用改变,
    也可以自定义style,但做法跟这个一样,只不过名字换了。但是这种在6.0系统上,我感觉黑色的字体变浅了
    ,不知道咋回事,求大神告知

<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    
        <item name="windowNoTitle">true</item>  
    </style>
 <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">>



2.不依赖android-support-v7-appcompat

2.1,这种的话网上很多,基本都对

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//去除标题栏
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
2.2,在style下多加个item,其余不变
        <style name="AppTheme" parent="AppBaseTheme">
            <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    
          <item name="windowNoTitle">true</item>  
         </style>



2.3,在application节点下的theme主题换下

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar">

 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值