样式styles和主题theme

 

参考资料:http://blog.csdn.net/sshhbb/article/details/7219838/

 

/values/styles.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">     //这个是主题,继承与DarkActionBar
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>
    <style name="buttonstyle">   //这个为自己添加的
        <item name="android:layout_width">wrap_content</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:text">heihei</item>
    </style>

</resources>

/layout/Activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="sample.android_serialport_api.myapplication.MainActivity">
  ...
    <Button
        style="@style/buttonstyle"   //在这里使用的style
        android:id="@+id/butto6"/>
    <Button
        style="@style/buttonstyle"
        android:id="@+id/butto7"/>
    <Button
        style="@style/buttonstyle"
        android:id="@+id/butto8"/>
</LinearLayout>

 

manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="sample.android_serialport_api.myapplication">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">     //在这里使用的主题
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

 

 

posted on 2017-11-08 19:09  maogefff  阅读(368)  评论(0编辑  收藏  举报

导航