Android Studio 的坑

来源:互联网 发布:刘松 软件 编辑:程序博客网 时间:2024/06/05 23:40

1.activity里去掉标题栏 

android studio 版本是 1.2.1.1

    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        requestWindowFeature(Window.FEATURE_NO_TITLE);        setContentView(R.layout.activity_main);}
编译是没有问题的,运行起来就会报错 

Caused by: android.util.AndroidRuntimeException: requestFeature() must be called before adding content

我试过将requestWindowFeature放在super.onCreate前面,虽然不报错了,但是去标题栏的功能没有实现。通过配置layout.xml也试过了,一样报错。

最后解决办法是

<activity    android:name=".WebViewActivity"    android:label="@string/title_activity_web_view"    android:theme="@style/Theme.AppCompat.NoActionBar"></activity>

就是在AndroidManifest.xml修改android:theme为:"@style/Theme.AppCompat.NoActionBar",这样就不报错,去标题栏的功能也实现了。




0 0
原创粉丝点击