【问题标题】:How to make background Image to fill fullscreen in android?如何使背景图像在android中填充全屏?
【发布时间】:2020-12-19 12:39:54
【问题描述】:

大家!我尝试使用以下代码使我的启动画面充满整个屏幕:

在styles.xml文件中:

<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.EBanking" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
    <!-- Primary brand color. -->
    <item name="colorPrimary">@color/purple_500</item>
    <item name="colorPrimaryVariant">@color/purple_700</item>
    <item name="colorOnPrimary">@color/white</item>
    <!-- Secondary brand color. -->
    <item name="colorSecondary">@color/teal_200</item>
    <item name="colorSecondaryVariant">@color/teal_700</item>
    <item name="colorOnSecondary">@color/black</item>
    <!-- Status bar color. -->
    <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
    <!-- Customize your theme here. -->
</style>

<style name="ColdFullscreen" parent="Theme.EBanking">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:background">@drawable/splash_background</item>
</style>

在 Manifest.xml 文件中:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.themirrorcode.ebanking">
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/Theme.EBanking">
    <activity android:name=".MainActivity"
        android:theme="@style/ColdFullscreen">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

activity_layout.xml 代码:

<androidx.constraintlayout.widget.ConstraintLayout 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"
tools:context=".MainActivity"/>

应用背景不是全屏,请看图。 谢谢! App Result

编辑

想让图片全屏显示。上面链接中提到了

【问题讨论】:

    标签: java android android-studio fullscreen


    【解决方案1】:

    改变这一行

    <style name="Theme.EBanking" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
    

    到这里

    <style name="Theme.EBanking" parent="Theme.MaterialComponents.DayNight.NoActionBar">
    

    然后添加 android:background="@drawable/splash_background" 到 activity_layout.xml 并从您的 Manifest.xml 文件中删除 android:theme="@style/ColdFullscreen"

    【讨论】:

    • 将 Manifest.xml 文件的整个代码和应用中布局的代码添加到您的问题中
    • 我已根据您的需要编辑了我的问题。谢谢你们的cmets。
    • 我编辑了我的答案,别忘了也改成NoActionBar
    • 没有变化,当我隐藏 ActionBar 和 TitleBar 时。请在我上面的问题中查看附图。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-31
    • 1970-01-01
    • 2011-07-13
    • 2011-12-26
    • 2018-10-02
    相关资源
    最近更新 更多