안드로이드 스튜디오에서 버튼을 생성했을 때 배경이 변하지 않을 때
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:text="Button"
android:background="#ffff00"
tools:layout_editor_absoluteX="70dp"
tools:layout_editor_absoluteY="60dp" />
다음과 같이 배경색을 #ffff00(노란색) 으로 지정했지만
배경 색이 변하지 않았을 때
1. res - values - themes 클릭
2. 클릭시 나오는 코드
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Round_button" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
이 코드 중
<style name="Theme.Round_button" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
이 부분의 parent 내용을
"Theme.AppCompat.Light" 으로 작성.
설정대로 버튼의 배경 색이 설정되는 것을 볼 수 있다.
'Android' 카테고리의 다른 글
Android] Intent (0) | 2022.01.24 |
---|---|
Android] ImageButton 이미지 크기 조절 (0) | 2022.01.19 |
Android] Button 모양 설정 (0) | 2022.01.16 |
Android] Button 클릭 시 화면 전환(Intent사용) (0) | 2022.01.12 |
Andriod] Constraintlayout 정렬 (0) | 2022.01.11 |