简体   繁体   中英

How to change my android application's theme?

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

Use appcompat in your app, it gives some of the good things from lollipop to all pre-lollipop supported apps. http://android-developers.blogspot.in/2014/10/appcompat-v21-material-design-for-pre.html I have mimicked complete material design using appcompat.

Widgets supported by appcompat are:

  • EditText
  • Spinner
  • CheckBox
  • RadioButton
  • Switch (use the new android.support.v7.widget.SwitchCompat)
  • CheckedTextView

For styling button use the below style:

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

Also you can use this library to prep up your app with material design, https://github.com/navasmdc/MaterialDesignLibrary

To change button style, you can change its background. Here is an example for you. Follow these steps:

1. Define button background

For example:

   <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. Create a new folder in res folder

Right click on res folder in your project > New > Folder. Name it with drawable .

3. Create a new xml file for your button background

Here, we can name it with button_background.xml . You may rename it later. Place it in drawable folder. So, fill it with:

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

And, completed... For information about changing app's theme, this is a reference for you: Styles and Themes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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