https://sectumsempra.tistory.com/75
์ ๊ธ๊ณผ ์ด์ด์ง๋ ๋ด์ฉ์ ๋๋ค.
๋ฒํผ ๋ง๋ค๊ธฐ
drawable ํด๋ ์๋์ ์๋ก์ด layoutํ์ผ์ ๋ง๋ค๊ณ ์๋์ ๊ฐ์ด ์ ๋ ฅํ์.
bbb.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
//ํฌ๊ธฐ ์ค์
<size android:width="200dp" android:height="120dp"/>
//ํ
๋๋ฆฌ ์ค์ (์ ๊ตต๊ธฐ/์๊น)
<stroke android:width="1dp" android:color="#0000ff"/>
//์ฑ์ฐ๊ธฐ ์ ์ค์
<solid android:color="#aabbff"/>
//์๋ ์ฌ๋ฐฑ
<padding android:bottom="1dp"/>
</shape>
์๊ณผ ๊ฐ์ด ๋ฒํผ์ ์ถ๊ฐํ๊ณ ๋ฐฐ๊ฒฝ์ ์ค์ ํ๋ค.
์ค์ ๊ฐ๊ณผ ์์ค ์ฝ๋๋ ์๋์ ๊ฐ๋ค.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bbb"
android:text="Button"
app:backgroundTint="@android:color/transparent"
app:backgroundTintMode="add"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.499" />
</androidx.constraintlayout.widget.ConstraintLayout>
๋ฐฐ๊ฒฝ ๋ณ๊ฒฝํ๊ธฐ
์ดํ ๋ฐฐ๊ฒฝ์์ ๋ฐ๊พธ๊ธฐ ์ํด drawable ํด๋ ์๋์ background.xmlํ์ผ์ ์๋ก ๋ง๋ ๋ค. ์ฝ๋๋ ์๋์ ๊ฐ๋ค.
background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#7288DB"
android:centerColor="#3250B4"
android:endColor="#254095"
android:angle="90"
android:centerY="0.5"/>
<corners android:radius="2dp"/>
</shape>
๊ทธ๋ฆฌ๊ณ activity_main์์ ๋ฐฐ๊ฒฝ์ ์๋์ ๊ฐ์ด ๋ณ๊ฒฝํ๋ค.
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bbb"
android:text="Button"
app:backgroundTint="@android:color/transparent"
app:backgroundTintMode="add"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.499" />
</androidx.constraintlayout.widget.ConstraintLayout>
ํ ๋๋ฆฌ๋ง ์๋ ๋ฒํผ ๋ง๋ค๊ธฐ
btn.xmlํ์ผ์ drawable ํด๋ ์๋์ ๋ง๋ค์ด ์๋์ ๊ฐ์ด ์ฝ๋๋ฅผ ์ ๋ ฅํ๋ค.
<layer-list>ํ๊ทธ๋ฅผ ์ด์ฉํด ์ฌ๋ฌ๊ฐ์ ๊ทธ๋ํฝ์ ํ๋์ XMLํ์ผ์ ๋ฃ์ ์ ์๋ค.
btn.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<stroke android:width="1dp" android:color="#BE55DA"/>
<solid android:color="#00000000"/>
<size android:width="200dp" android:height="100dp"/>
</shape>
</item>
<item android:top="1dp" android:bottom="1dp"
android:right="1dp" android:left="1dp">
<shape android:shape="rectangle">
<stroke android:width="1dp" android:color="#FF55DA"/>
<solid android:color="#00000000"/>
</shape>
</item>
</layer-list>
์์์ ํ๋๋๋ก ๋ฒํผ์ ํ๋ ๋ง๋ค์ด btn2.xml์ background์ ์ง์ ํ๋ฉด ์๋์ ๊ฐ์ ํ๋ฉด์ ๋ณผ ์ ์๋ค.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bbb"
android:text="Button"
app:backgroundTint="@android:color/transparent"
app:backgroundTintMode="add"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.499" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/btn2"
android:text="Button"
app:backgroundTint="@android:color/transparent"
app:backgroundTintMode="add"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="170dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
'APP' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Firebase+Android Studio] ์ฑ์ ๋ก๊ทธ์ธ ๊ธฐ๋ฅ ์ถ๊ฐํ๊ธฐ 1 (0) | 2021.07.26 |
---|---|
[์ํ ๋๋ก์ด๋ธ(StateListDrawable)] ์ด๋ฏธ์ง ๋ฒํผ ๋ง๋ค๊ธฐ ๋ฐ ์ด๋ฏธ์ง ๋ฐ๊พธ๊ธฐ (0) | 2021.07.12 |
JAVA 2 - ์ดํด๋ฆฝ์ค ์ค์นํ๊ธฐ (0) | 2021.02.07 |
JAVA 1-JDK ์ค์นํ๊ธฐ (0) | 2021.02.06 |
๋๊ธ