简体   繁体   English

如何在 Android Studio 中隐藏启动活动的导航栏?

[英]How to hide a navigation bar for splash activity in Android Studio?

I am new in a Android.我是 Android 新手。 I would like to hide a navigation bar only for splash activity.我想仅为启动活动隐藏导航栏。

I have written a below code to hide Action Bar.我编写了以下代码来隐藏操作栏。 But this code is unable to hide my navigation bar -但此代码无法隐藏我的导航栏 -

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

And this is my splash_activity -这是我的 splash_activity -

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
    android:gravity="center_vertical|center_horizontal"
    android:background="#b7eaea"
    tools:context=".SplashActivity">

    <com.felipecsl.gifimageview.library.GifImageView
        android:id="@+id/loader"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

And This is my Java code.这是我的 Java 代码。 Please let me know if any changes.请让我知道是否有任何变化。

package com.example.user.boat;

import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.felipecsl.gifimageview.library.GifImageView;

import org.apache.commons.io.IOUtils;

import java.io.IOException;
import java.io.InputStream;

public class SplashActivity extends AppCompatActivity {

    private static int SPLASH_TIME_OUT = 8000;
    private GifImageView gif;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        gif = (GifImageView)findViewById(R.id.loader);

        try{
            InputStream inputStream = getAssets().open("splash" +
                    ".gif");
            byte[] bytes = IOUtils.toByteArray(inputStream);
            gif.setBytes(bytes);
            gif.startAnimation();
        } catch (IOException e) {
            e.printStackTrace();
        }

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent home = new Intent(SplashActivity.this, DashboardActivity.class);
                startActivity(home);
                finish();
            }
        },SPLASH_TIME_OUT);
    }
}

Thanks in advance.提前致谢。

你可以试试

parent="Theme.AppCompat.Light.NoActionBar"

You can set it programatically like this :您可以像这样以编程方式设置它:

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

Put these two lines of code before setContentView(R.layout.activity_splash_screen);将这两行代码放在setContentView(R.layout.activity_splash_screen);

尝试隐藏在 onCreate 方法中

getSupportActionBar().hide();

AndroidManifest.xml AndroidManifest.xml

<activity
    android:name=".SplashActivity"
    android:theme="@style/AppTheme.NoActionBar" />

styles.xml样式文件

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM