Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Tags more
Archives
Today
Total
관리 메뉴

맨땅에 코딩

안드로이드 레이아웃 백그라운드 배경색 설정(벡터 드로어블 이용) 본문

앱 개발/Java

안드로이드 레이아웃 백그라운드 배경색 설정(벡터 드로어블 이용)

맨땅 2022. 4. 5. 14:57

목차

    반응형

     

     

    배경을 아래 사진처럼 대각선으로 그라데이션 없이 나눠주고 싶었다.

     

     

     

     

     

    drawable에 backgroundcolorsetting.xml 파일을 하나 만들어준다

     

     

    [backgroundcolorsetting.xml]

    <?xml version="1.0" encoding="utf-8"?>
    <vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:height="100dp"
        android:width="100dp"
        android:viewportHeight="100"
        android:viewportWidth="100">
    
    
        <path
            android:name="light_triangle"
            android:fillColor="#7983D7"
            android:pathData="M 0,0 L 100,0 0,100 z" />
    
        <path
            android:name="dark_triangle"
            android:fillColor="#8790DB"
            android:pathData="M 100,0 L 0,100 100,100 z" />
    
    </vector>

     

     

    이후 저 배경색의 레이아웃을 사용할 xml파일에 와서 작성해줍니다.

     

     

     

    [activity_main.xml]

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/backgroundcolorsetting"
        android:orientation="vertical">

    코드를 보시면 background="@drawable/작성하신 레이아웃이름" 을 입력해주시면 됩니다

     

     

     

     

    그라데이션을 주시고 싶으시면 아래 코드를 활용해서 작성하시면 됩니다

     

     

    <?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:endColor="#879000"/>
    </shape>
    반응형