27

我试图弄清楚如何隐藏启动屏幕活动的操作栏。我做了一些事情,在我的启动画面上隐藏了我的操作栏,但是有一个问题:在我的启动画面出现之前,有一个带有操作栏的活动,它会短暂出现......我不知道如何隐藏它!

我的启动画面只有在我们第一次触摸应用程序时才会出现,就像应用程序的介绍一样。

代码 :

package com.example.basicmaponline;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;

public class Intro extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);


    getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
    getActionBar().hide();

    setContentView(R.layout.intro);

    Thread timer = new Thread(){
        public void run(){
            try{
                sleep(3000);
            }catch (InterruptedException e) {
                e.printStackTrace();
            }finally{
                Intent openMenu = new Intent("com.example.basicmaponline.MENU");
                startActivity(openMenu);
            }
        }
    };
    timer.start();
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    finish();
}

}

显现 :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.basicmaponline"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.CALL_PHONE"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_GPS"></uses-permission>

<application
    android:allowBackup="true"
    android:icon="@drawable/lojacidadao"
    android:label="@string/app_name"
     android:theme="@style/AppTheme">
    <activity
        android:name="com.example.basicmaponline.Intro"
        android:screenOrientation="portrait"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name="com.example.basicmaponline.Menu"
        android:screenOrientation="portrait"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="com.example.basicmaponline.MENU" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <activity
        android:name="com.example.basicmaponline.Mapa"
        android:screenOrientation="portrait"
        android:label="@string/map_name">
        <intent-filter>
            <action android:name="com.example.basicmaponline.MAPA" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.example.basicmaponline.Lojas"
        android:screenOrientation="portrait"
        android:label="@string/lojas_name">
        <intent-filter>
            <action android:name="com.example.basicmaponline.LOJAS" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <activity
        android:name="com.example.basicmaponline.InfoLoja"
        android:screenOrientation="portrait"
        android:label="@string/loja_name">
        <intent-filter>
            <action android:name="com.example.basicmaponline.INFOLOJA" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <activity
        android:name="com.example.basicmaponline.Balcoes"
        android:screenOrientation="portrait"
        android:label="@string/balcoes_name" >
        <intent-filter>
            <action android:name="com.example.basicmaponline.BALCOES" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <activity
        android:name="com.example.basicmaponline.Entidade"
        android:screenOrientation="portrait"
        android:label="@string/balcao_name">
        <intent-filter>
            <action android:name="com.example.basicmaponline.ENTIDADE" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

     <activity
        android:name="com.example.basicmaponline.Servicos"
        android:screenOrientation="portrait"
        android:label="@string/servicos_name">
        <intent-filter>
            <action android:name="com.example.basicmaponline.SERVICOS" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

     <activity
        android:name="com.example.basicmaponline.InfoServico"
        android:screenOrientation="portrait"
        android:label="@string/servico_name">
        <intent-filter>
            <action android:name="com.example.basicmaponline.INFOSERVICO" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

     <activity
        android:name="com.example.basicmaponline.Pesquisar"
        android:screenOrientation="portrait"
        android:label="@string/pesquisa_name" >
        <intent-filter>
            <action android:name="com.example.basicmaponline.PESQUISAR" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

</application>
</manifest>
4

5 回答 5

59

为什么不将第一个活动的主题添加到清单中以排除操作栏,甚至可能是通知栏?

就像是:

<application
    android:allowBackup="true"
    android:icon="@drawable/lojacidadao"
    android:label="@string/app_name"
     android:theme="@style/AppTheme">
    <activity
        android:name="com.example.basicmaponline.Intro"
        android:screenOrientation="portrait"
        android:label="@string/app_name" 
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
 ...

如果您扩展普通Activity类,这应该可以工作。

如果您的 ActivityAppCompatActivity改为扩展,请使用此主题,例如:

  <style name="AppTheme.Splash" parent="@style/Theme.AppCompat.NoActionBar">
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
  </style>

意义 :

 <activity ...            
    android:theme="@style/AppTheme.Splash" >
    ...

顺便说一句,您拥有操作栏的原因是因为您在应用程序标签中设置了默认主题,所以它不是您之前的活动,它实际上是您自己的启动活动。

于 2013-05-29T20:56:49.563 回答
7

如果您的构建目标 sdk 5.0 或更高版本(AppTheme 样式为 Theme.AppCompat.Light.DarkActionBar。)

<activity
    android:name=".Splash"
    android:label="@string/app_name"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity>
于 2015-02-02T21:34:18.790 回答
2

你的问题是这些线

getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();

它们不是必需的,因为根本不需要ActionBar调用它们,启动屏幕不使用一个,并且应该与Activity其他屏幕完全分开。

你需要两个Activities。一个用于具有自己布局的启动画面。第二个是 main Activity,可以是登录屏幕或欢迎屏幕等。

闪屏类应该是这样的

public class SplashScreen extends Activity {

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

    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.yourlayoutfile);

    Thread loading = new Thread() {
        public void run() {
            try {
                sleep(5000);
                Intent main = new Intent(SplashScreen.this, Main.class);
                startActivity(main);
            }

            catch (Exception e) {
                e.printStackTrace();
            }

            finally {
                finish();
            }
        }
    };

    loading.start();
}

}

XML 文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"    
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"    
tools:context=".SplashScreen" >

// if not using an image replace with whatever is to be shown on the splash screen
<ImageView  
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/logo" />

</LinearLayout>

现在第二个ActivityActionBar等的布局。

于 2013-05-29T20:28:25.803 回答
1

小而甜,容易

在 OnCreate 中执行

View decorView = getWindow().getDecorView();
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
于 2019-09-19T06:39:47.883 回答
0
//add to AndroidManifest for SplashScreen
<activity
         android:name="<YOUR_PACKAGENAME.ACTIVITY>"
         android:theme="@style/AppTheme.NoActionBar"
         .........../>
//add this styles to  styles.xml

 <style name="AppTheme.NoActionBar">
    <item name="android:background">@android:color/transparent</item>
    <item name="android:windowDisablePreview">true</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowBackground">@null</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

//add this code to Activity
public class SplashScreen extends AppCompatActivity {
.
.
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    .
    .
    .
    }

}
于 2019-08-17T05:12:27.073 回答