How to set the background of the android application?

后端 未结 4 1000
遥遥无期
遥遥无期 2021-02-05 11:31

I want to change the background of my App\'s Activity.

Now that is available in black I want to change that with some images or themes.

相关标签:
4条回答
  • 2021-02-05 12:04

    Further to @Ryan:

    In the layout for your activities, you can also add the attribute

    android:background="@android:color/white"
    

    to set a background color. You can also introduce a custom resource /res/values/colors.xml in which you can declare custom colors. One such file might look like:

    <resources>
    <color name="fire_brick_red">#B0171F</color>
    </resources>
    

    You then introduce these in XML as follows:

    android:background="@color/fire_brick_red"
    
    0 讨论(0)
  • 2021-02-05 12:06

    Personally, I would try to do it in xml like Sk9 suggests, but programmatically at runtime you can do

    setBackgroundColor(int color)
    

    or

    setBackgroundResource(int resourceID)
    

    Source: http://developer.android.com/reference/android/view/View.html

    0 讨论(0)
  • 2021-02-05 12:08

    Add a android:theme="@style/Theme.AppTheme attribute to your application tag in the manifest file with the theme you want to use. This will prevent the default "black" background to be drawn if you only set a background in your Activity/Fragment layout file.

    You declared it in a style.xml file.

    <?xml version="1.0" encoding="utf-8"?>
    <resources>    
    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="@style/Theme">
    <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
    -->
    </style>
    </style>
        <!-- Application theme. -->
        <style name="AppTheme" parent="AppBaseTheme">
            <!-- All customizations that are NOT specific to a particular API-level can go here. -->
            <item name="android:windowBackground">@drawable/custom_background</item>
        </style>
    
    </resources>
    

    AndroidManifest.xml file

    ...
    <application
        android:name="@string/app_name"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/Theme.AppTheme">
    ...
    
    0 讨论(0)
  • 2021-02-05 12:11

    Add the background attribute to your window's xml layout. Example:

    <LinearLayout android:background="@drawable/yourbackgroundimage" ... >   
    
    0 讨论(0)
提交回复
热议问题