Android Studio App设置Activity背景图片

1.首先PC上要有一张png格式的图片,复制它,注意图片名字(只能含小写字母a~z和数字0~9,".png“要小写),粘贴进drawable文件夹。

 

2.在activity_main.xml里添加下面一句,注意添加位置,/drawable/+图片名称。

 

android:background="@drawable/backimg"

整个activity_main.xml内容如下:

 

 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="0dp"
    android:paddingRight="0dp"
    android:paddingTop="0dp"
    android:paddingBottom="0dp" tools:context=".MainActivity"
    android:background="@drawable/backimg"
    >
    <TextView
        android:text="hello,world!"
        android:textSize="50dp"
        android:textColor="#FFFFFF"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
</RelativeLayout>


3.完成,实际效果如下:

 

 

 

Android Studio设置应用的启动屏幕或全屏背景图片,通常是在Manifest.xml文件中的`<activity>`标签中完成。以下是步骤: 1. **打开`res/layout/activity_main.xml`**:这是应用的主要布局文件,一般用来设定启动界面。 2. **找到`<application>`标签**:在其中添加`<meta-data>`元素,用来指定启动画面(Splash Screen)。 ```xml <meta-data android:name="android:splashscreen" android:resource="@drawable/splash_screen" /> ``` 这里的`@drawable/splash_screen`需要替换为你应用中的启动图片资源ID,通常是`.png`或`.jpg`格式的图片。 3. **创建或编辑`@drawable/splash_screen`资源**:在`res/drawable`目录下创建或编辑你的启动图片。记得调整大小以便适应不同的设备分辨率。 4. **如果需要渐变动画或延迟展示**,可以使用`<activity>`下的`android:theme`属性设置`@style/SplashTheme`,并在styles.xml中定义样式: ```xml <style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:windowBackground">@drawable/splash_gradient</item> <item name="android:allowBackup">false</item> <item name="android:configChanges">orientation|screenSize</item> <item name="android:theme">@android:style/Theme.Translucent</item> <!-- 添加其他过渡效果 --> </style> ``` 然后在`<activity>`里引用这个主题: ```xml <activity android:name=".YourActivity" android:theme="@style/SplashTheme" android:launchMode="singleTop"> <!-- 其他配置 --> </activity> ``` 5. **等待一段时间后跳转到主界面**:在`onCreate()`方法中添加适当的延迟逻辑,然后调用`finish()`关闭当前活动并启动主界面。 完成以上步骤后,当用户首次打开你的应用时,就会看到预设的背景图片了。
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值