繁体   English   中英

如何在Android Studio中获得全屏活动

[英]howto get full screen activity in android studio

我试图制作一个初始屏幕,我希望它是全屏的,没有工具栏,因为那我将splashscreen.xml的主题更改为全屏,在设计视图中,一切看起来都很完美,但是当我在模拟器上启动应用程序时它再次出现在工具栏上。

我的androidmenifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.shiftind.www.shiftind">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".SplashScreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            android:label="@string/app_name"
            android:launchMode="singleTask"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar"
            android:screenOrientation="landscape" >
        </activity>
        <activity android:name=".MainActivity"></activity>
        <activity android:name=".registration" />
        <activity android:name=".login" />
        <activity android:name=".SignUp" />
    </application>

</manifest>

*My splashscreen.xml*

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_splash_screen"
    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"
    tools:context="com.shiftind.www.shiftind.SplashScreen"
    android:background="@drawable/shiftind">



</RelativeLayout>

我的SplashScreen.java

package com.shiftind.www.shiftind;

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

public class SplashScreen extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash_screen);
        Thread MyThread = new Thread(){
            @Override
            public void run() {
                try {
                    sleep(3000);
                    Intent intent = new Intent(getApplicationContext(), MainActivity.class);
                    startActivity(intent);
                    finish();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };
        MyThread.start();
    }
}

尝试手动定义主题并在那里设置属性。 themes.xml

<style name="MyThemeNoBar" parent="@style/Theme.AppCompat.Light">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

AndroidManifest.xml ,将SplashScreen的主题设置为:

android:theme="@style/MyThemeNoBar"

编辑 :我还添加了android:windowFullscreenandroid:windowContentOverlay android:windowFullscreen (来源: https android:windowFullscreen

您的AndroidManifest已损坏,以下是更正:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".SplashScreen"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar"
        android:screenOrientation="landscape" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".MainActivity"></activity>
    <activity android:name=".registration" />
    <activity android:name=".login" />
    <activity android:name=".SignUp" />
</application>

您可以通过编程方式执行此操作( 请参阅android示例 ):

public void toggleHideyBar() {
    // The UI options currently enabled are represented by a bitfield.
    // getSystemUiVisibility() gives us that bitfield.
    int uiOptions = getActivity().getWindow().getDecorView().getSystemUiVisibility();
    int newUiOptions = uiOptions;
    boolean isImmersiveModeEnabled =
            ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions);
    if (isImmersiveModeEnabled) {
        Log.i(TAG, "Turning immersive mode mode off. ");
    } else {
        Log.i(TAG, "Turning immersive mode mode on.");
    }

    // Immersive mode: Backward compatible to KitKat (API 19).
    // Note that this flag doesn't do anything by itself, it only augments the behavior
    // of HIDE_NAVIGATION and FLAG_FULLSCREEN.  For the purposes of this sample
    // all three flags are being toggled together.
    // This sample uses the "sticky" form of immersive mode, which will let the user swipe
    // the bars back in again, but will automatically make them disappear a few seconds later.
    newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
    newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;
    newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
    getActivity().getWindow().getDecorView().setSystemUiVisibility(newUiOptions);
}

就我而言,我正在使用满足我要求的东西!

在“活动”中,在Oncreate方法中使用以下代码

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        this.requestWindowFeature(Window.FEATURE_NO_TITLE);

并在您的样式中设置如下

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>


    </style>

</resources>

如果仍然在评论中提到混乱,请:-)

暂无
暂无

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

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