如何从 android 活动中删除标题栏?

新手上路,请多包涵

有人可以帮我解决这个问题吗?我希望我的活动是全屏的,并想从屏幕上删除标题。我尝试了几种方法,但无法删除它。

活动代码:

 public class welcomepage extends Activity {
    private Button btn;
    EditText userName,passWord;
    DatabaseHandler dbHandler;
    Context ctx =this;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //Remove title bar
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_welcomepage);
   }
}

和Activity.xml

 <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="@drawable/pic1"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.edkul.vimal.edkul.welcomepage">

</RelativeLayout>

我想删除以蓝色显示的标题栏。请查找图像以供参考:

在此处输入图像描述

AndroidManifest.xml

 <application
        android:minSdkVersion="3"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/Theme.AppCompat.NoActionBar">
        <activity
            android:name=".welcomepage"
            android:label="@string/app_name"
            android:theme="@style/Theme.AppCompat.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category    android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
</application>

原文由 vimal mishra 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 604
2 个回答

尝试这个:

this.getSupportActionBar().hide();

 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try
    {
        this.getSupportActionBar().hide();
    }
    catch (NullPointerException e){}

    setContentView(R.layout.activity_main);
}

原文由 Christer 发布,翻译遵循 CC BY-SA 3.0 许可协议

加入活动

requestWindowFeature(Window.FEATURE_NO_TITLE);

并使用以下两行添加您的 style.xml 文件:

 <item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>

原文由 Soumen Das 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题