본문 바로가기

Programming/[Android Studio]

[Android Studio] 그라데이션 효과 넣기

 

 

Drawable에 xml파일을 만든다.

 

1
2
3
4
5
6
7
8
9
10
11
12
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient
        android:angle="45"                //어느 방향으로 그라데이션 효과를 넣을지 정할  있다
        android:type="linear"
        android:startColor="#247dea"    //시작 
        android:centerColor="#18c6ff"    //가운데 
        android:endColor="#247dea"/>    //끝 색
    <corners
        android:radius="20dp"/>        //끝부분을 둥글게 할 수 
</shape>
 
cs

 

 

렇게 코드를 넣어준 뒤

 

사용할 때는 Java에서 부르는 방법과 layout xml에서 부르는 방법이 있다.

 

자바에서 부르는 방법

1
textView.setBackgroundResource(R.drawable.background);
cs

 

xml에서 부르는 방법

1
android:background="@drawable/controller"
cs