繁体   English   中英

如何更改我的android应用程序的主题?

[英]How to change my android application's theme?

我该如何更改应用程序的主题按钮和其他东西处于普通外观。我只想更改那些普通外观。

在您的应用程序中使用appcompat,它提供了从棒棒糖到所有棒棒糖之前支持的所有应用程序的一些好处。 http://android-developers.blogspot.in/2014/10/appcompat-v21-material-design-for-pre.html我使用appcompat模仿了完整的材料设计。

appcompat支持的小部件为:

  • 的EditText
  • 微调
  • 复选框
  • 单选按钮
  • 切换(使用新的android.support.v7.widget.SwitchCompat)
  • CheckedTextView

对于样式按钮,请使用以下样式:

<style name="Button">
    <item name="android:textColor">@color/white</item>
    <item name="android:padding">0dp</item>
    <item name="android:minWidth">88dp</item>
    <item name="android:minHeight">36dp</item>
    <item name="android:layout_margin">3dp</item>
    <item name="android:elevation">1dp</item>
    <item name="android:translationZ">1dp</item>
    <item name="android:background">@drawable/primary_round</item>
</style>

您也可以使用此库通过材质设计为您的应用做准备, https://github.com/navasmdc/MaterialDesignLibrary

要更改按钮样式,可以更改其背景。 这是给你的例子。 跟着这些步骤:

1.定义按钮背景

例如:

   <Button
        android:id="@+id/myButton"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="25dp"
        android:background="@drawable/button_background" // this is your button background
        android:text="@string/myButton"
        android:textColor="@color/white"/>

2.在res文件夹中创建一个新文件夹

右键单击项目中的res文件夹>新建>文件夹。 drawable命名。

3.为您的按钮背景创建一个新的xml文件

在这里,我们可以使用button_background.xml对其进行button_background.xml 您可以稍后重命名。 将其放在可绘制的文件夹中。 因此,请填写:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <!-- view background color-->
    <solid android:color="@color/your_background_color" >
    </solid>

    <!-- If you want to add some padding -->
    <padding
        android:left="5dp"
        android:top="5dp"
        android:right="5dp"
        android:bottom="5dp" />

    <!-- Here is the corner radius -->
    <corners
        android:radius="6dp"   >
    </corners>

</shape>

并且,完成...有关更改应用程序主题的信息,这是给您的参考: 样式和主题

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM