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