如何在android中制作背景图片来填充全屏?

vdzxcuhz  于 2021-06-29  发布在  Java
关注(0)|答案(2)|浏览(559)

所有人!我尝试使用下面的代码使我的启动屏幕充满整个屏幕:
在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\ u 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"/>

应用背景不是全屏,请看图片。谢谢您!应用程序结果
编辑
希望图像采取全屏。这是提到在上面的链接

x9ybnkn6

x9ybnkn61#

添加framelayout如下所示,并在其工作模式中设置图像。

<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">
<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/yourImage">
</FrameLayout>

</androidx.constraintlayout.widget.constraintlayout>

ghhkc1vu

ghhkc1vu2#

更改此行

<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并删除 android:theme="@style/ColdFullscreen" 从manifest.xml文件

相关问题