去除app中的标题栏

我之前一直用的是在oncreate方法中添加 requestWindowFeature(Window.FEATURE_NO_TITLE),并且必须写在setContentView(R.layout.activity_main)之前

1    @Override
2     protected void onCreate(Bundle savedInstanceState) {
3         super.onCreate(savedInstanceState);
4         requestWindowFeature(Window.FEATURE_NO_TITLE);
5         setContentView(R.layout.activity_main);
}

结果不起作用,结果百度了很多方法,终于解决了,因为我的activity 继承的是AppCompatActivity,所以在清单文件manifest中,添加android:theme="@style/Theme.AppCompat.Light.NoActionBar"

 1 <application
 2         android:allowBackup="true"
 3         android:icon="@mipmap/ic_launcher"
 4         android:label="@string/app_name"
 5         android:supportsRtl="true"
 6         android:theme="@style/Theme.AppCompat.Light.NoActionBar">
 7         <!--android:theme="@style/AppTheme"-->
 8 
 9 
10         <activity android:name=".MainActivity">
11             <intent-filter>
12                 <action android:name="android.intent.action.MAIN" />
13 
14                 <category android:name="android.intent.category.LAUNCHER" />
15             </intent-filter>
16         </activity>
17     </application>

就解决了,虽然是小问题,但找到解决方法也不好找,就在这里跟大家分享了

posted on 2016-12-07 10:02  oooo呼呼  阅读(211)  评论(0编辑  收藏  举报