I am setting style to my splash screen activity and in style I am adding background gradient, Now I am trying to add image at the center of screen, actually just below the center of screen lets say 20dp below the center. can any one tell me how I can active it.
Style I am adding to activity:
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">
@drawable/background_splash
</item>
<item name="android:buttonStyle">
@style/Base.Widget.AppCompat.Button.Colored
</item>
<item name="colorAccent">
@color/white
</item>
<item name="colorPrimaryDark">
@color/blue.dark
</item>
</style>
background_splash.xml: please refer comment in file
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/splash_screen_gradient" />
// here I want to add Image here such that it will be we wrap_contect and
// 20dp below center of screen
</layer-list>
splash_screen_gradient.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
>
<item >
<shape>
<gradient
android:angle="270"
android:centerColor="#ff0000"
android:endColor="#00ff00"
android:startColor="#0000ff">
</gradient>
</shape>
</item>
</layer-list>
I have tried several permutation combinations by adding Bitmap, Item background in layer list but its not working as expected. I don't want to add it in layout xml file.
To import image resources into your project, do the following: Drag and drop your images directly onto the Resource Manager window in Android Studio. Alternatively, you can click the plus icon (+), choose Import Drawables, as shown in figure 3, and then select the files and folders that you want to import.
A drawable resource is a general concept for a graphic that can be drawn to the screen and which you can retrieve with APIs such as getDrawable(int) or apply to another XML resource with attributes such as android:drawable and android:icon . There are several different types of drawables: Bitmap File.
In Android Studio, click on View > Tool Windows > Resource Manager in the menus or click on the Resource Manager tab to the left of the Project window. Click the + below Resource Manager, and select Import Drawables. This opens a file browser.
Sometimes you want an outline around your shape and to do that you can use the stroke tag. You can specify the width and color of the outline using android:width and android:color.
Try This, it works for me
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/splash_screen_gradient" />
<item android:top="20dp">
<bitmap android:src="@drawable/ic_logo"
android:gravity="center_vertical|center_horizontal" />
</item>
</layer-list>
You can store image in drawawble and create an item
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/splash_screen_gradient" />
<item android:drawable="@drawable/your_image" />
</layer-list>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With