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

时间:2016-03-26 14:04:28

标签: android android-layout

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

活动代码:

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>

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

enter image description here

的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>

7 个答案:

答案 0 :(得分:81)

您只需在{value}文件夹中的style.xml文件中添加此样式

<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
</style>

之后,将style设置为AndroidManifest.xml文件

中的活动类
android:theme="@style/AppTheme.NoActionBar"

修改: - 如果您采用编程方式隐藏ActionBar,请在活动onCreate()方法中使用以下代码。

if(getSupportedActionbar()!=null)    
     this.getSupportedActionBar().hide();

如果你想从Fragment隐藏ActionBar,那么

getActivity().getSupportedActionBar().hide();

AppCompat v7 : - 在您不想要actiobBar Theme.AppComat.NoActionBarTheme.AppCompat.Light.NoActionBar的活动中使用以下主题,或者如果您想在整个应用中隐藏,请在<application... />中的AndroidManifest中设置此主题1}}。

  

在Kotlin:

onCreate()方法中添加此行代码,或者您可以使用上述主题。

if (supportActionBar != null)
        supportActionBar?.hide()

我希望这会对你有所帮助。

答案 1 :(得分:15)

试试这个:

<强> this.getSupportActionBar()隐藏();

foreach ($milestone['milestonesfases'] as $milestonesfase) 
{
    echo '<tr>';
    echo '<td>'. $milestonesfase['milestonefase_id'] . '</td>';
    echo '<td>'. $milestonesfase['milestonefase_titel']  . '</td>';
    echo '<td></td>';
    echo '</tr>';
}

答案 2 :(得分:3)

在Android Manifest文件中,确保该活动使用此(或)主题(基于)@style/Theme.AppCompat.NoActionBar 这会完全删除ActionBar,但不会使您的活动全屏显示。 如果您想让您的活动全屏,请仅使用此主题

@android:style/Theme.NoTitleBar.Fullscreen

或者你可以改变

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

requestWindowFeature(Window.FEATURE_NO_TITLE);
 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

这是我用来在运行时获得全屏的

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                mDecorView = getWindow().getDecorView();
                mDecorView.setSystemUiVisibility(
                        View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
                                | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                                | View.SYSTEM_UI_FLAG_IMMERSIVE);
            }

要退出全屏我使用此

mDecorView = getWindow().getDecorView();
mDecorView.setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

答案 3 :(得分:3)

您可以尝试:

<activity android:name=".YourActivityName"
          android:theme="@style/Theme.Design.NoActionBar">

对我有用

答案 4 :(得分:1)

添加活动 requestWindowFeature(Window.FEATURE_NO_TITLE);

并使用以下两行添加style.xml文件 -

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

答案 5 :(得分:0)

您只需在style.xml文件中添加以下代码行

cProfile

在AndroidManifest.xml文件中更改apptheme

<style name="AppTheme.NoTitleBar" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>

答案 6 :(得分:-1)

在style.xml中添加这两行

<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
相关问题