AI 摘要
本文介绍了Android开发中三个常见的UI样式问题及解决方法。首先,通过代码实现边框圆角化,提升按钮美观度。其次,利用代码设置背景颜色渐变,增强视觉层次感。最后,针对Button背景色修改无效的问题,指出需在themes.xml文件中将特定样式修改为MaterialComponents,以正确应用主题。
1.边框圆角化
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<!-- 填充的颜色 -->
<solid android:color="#EEB422" />
<!-- android:radius 弧形的半径 -->
<!-- 设置按钮的四个角为弧形 -->
<corners
android:radius="20dip" />
<!--也可单独设置-->
<!-- <corners -->
<!-- android:topLeftRadius="10dp"-->
<!-- android:topRightRadius="10dp"-->
<!-- android:bottomRightRadius="10dp"-->
<!-- android:bottomLeftRadius="10dp"-->
<!-- /> -->
**设置文字padding**
<!-- padding:Button里面的文字与Button边界的间隔 -->
<padding
android:left="5dp"
android:top="3dp"
android:right="5dp"
android:bottom="3dp"
/>
</shape>
2.背景颜色渐变
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<!--实现应用背景颜色渐变-->
<gradient
android:startColor="#FFF8DC"
android:endColor="#FFE1FF"
android:angle="270"/>
<corners
android:radius="20dip"
android:topLeftRadius="0dp"
android:topRightRadius="0dp"/>
</shape>
3.Button背景色修改无效
找到main/res/values/themes.xml文件
将其中的<style name="Theme.MyRegistration" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
修改为<style name="Theme.MyRegistration" parent="Theme.MaterialComponents.DayNight.DarkActionBar.Bridge">即可