How to set a background color with light focused towards the centre for an android activity in Android Studio?


Keywords:android 


Question: 

This link holds an image which has a plain blue background with light focused towards the center of the image.

How can I set a similar background color in Android Studio for an activity, without using 'drawable'?


2 Answers: 

Try this

<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient android:type="radial" android:gradientRadius="250"
    android:startColor="your_color" android:endColor="your_color" />
</shape>
 

Use gradient drawable in order to get that effect. Replace startColor & endColor as per the requirement & ensure that color value is having Opacity parameter.

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" 
               android:shape="rectangle">
        <gradient android:type="radial" android:gradientRadius="300"
                  android:startColor="#3bffffff" 
                  android:endColor="#72000000" />
    </shape>