Android 如何通过动态应用主题来更改文本视图、按钮和编辑文本的角的形状?

Android 如何通过动态应用主题来更改文本视图、按钮和编辑文本的角的形状?,android,android-widget,styles,themes,Android,Android Widget,Styles,Themes,这是我的密码。我从未见过我的申请有任何变化。我在resources/drawable中创建了这个。如何通过更改文本颜色、字体、形状等,为所有组件动态应用样式中的主题 <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval" android:padding="20dp">

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

 <?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>

在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>

android:shape=“rectangle”>
现在为您的按钮代码添加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
//shape是创建的xml文件的名称

在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>

android:shape=“rectangle”>
现在为您的按钮代码添加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
//shape是创建的xml文件的名称

您上面的代码运行得非常好。可能问题在于您声明后台的方式:您是在XML文件中还是通过Java代码动态地执行此操作?

您上面的代码工作得非常好。可能问题在于您声明后台的方式:您是在XML文件中还是在Java代码中动态执行此操作?

//在res/drawable//中创建形状//在Main.XML中创建形状//在res/drawable//中创建形状//在Main.XML中创建不是动态的,因为我注意到主题/样式不支持动态。所以我在用Xml工作。好的..刚刚看到了你的代码..试着动态声明背景。。Button Button=(Button)findviewbyid(r.id.yourid);setBackgroundResource(R.drawable.yourxmlfile);。。。我认为代码适合你是的,我注意到了。它已经改变了,特别是按钮形状。但我不应该用Java(活动)来称呼它。我需要在Xml文件中执行此操作。当我调用theme时,它必须完全动态地应用于我应用程序中的所有按钮。您的背景代码在我的xml文件中也可以正常工作。我认为您的@style/theme存在一些问题…发布主题代码不是动态的,因为我注意到主题/样式不支持动态。所以我在用Xml工作。好的..刚刚看到了你的代码..试着动态声明背景。。Button Button=(Button)findviewbyid(r.id.yourid);setBackgroundResource(R.drawable.yourxmlfile);。。。我认为代码适合你是的,我注意到了。它已经改变了,特别是按钮形状。但我不应该用Java(活动)来称呼它。我需要在Xml文件中执行此操作。当我调用theme时,它必须完全动态地应用于我应用程序中的所有按钮。你的背景代码在我的xml文件中也可以正常工作。我认为你的@style/theme有一些问题…发布主题代码