如何通过动态应用主题来更改textview,按钮,编辑文本的角落形状?

问题描述 投票:1回答:2

这是我的代码。我从未见过我的申请有任何变化。我在resources/drawable创建了这个。如何通过更改文本colorfontsshapes等动态地为所有组件应用样式中的主题。

 <?xml version="1.0" encoding="utf-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android"
 android:shape="oval" android:padding="20dp">
     <solid android:color="#FFA500"/>
     <corners android:bottomRightRadius="50dp" android:bottomLeftRadius="50dp"
     android:topLeftRadius="50dp" android:topRightRadius="50dp"/>
     <stroke android:color="#FFA500" android:dashWidth="50dp" />
 </shape>
android android-widget styles themes
2个回答
0
投票

你上面的代码工作得很好。也许问题在于您声明背景的方式:您是在XML文件中执行还是在Java代码中动态执行?


1
投票

在drawable中创建shape.xml

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" >
     android:shape="rectangle">
 <gradient
    android:startColor="#99CCFF"
    android:endColor="#99CCFF"
    android:angle="45"/>
 <padding android:left="6dp"
    android:top="6dp"
    android:right="6dp"
    android:bottom="6dp" />
 <corners android:radius="30dp" />
 </shape>

现在为你的Button代码添加android:background,如下所示。

  <Button
    android:id="@+id/bt"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/shape"/>  // shape is name of xml file created
© www.soinside.com 2019 - 2024. All rights reserved.