Android中浮動按鈕

目的:
(1)設置按鈕爲浮動按鈕
(2)設置爲按下時顏色與按下時顏色


1.build.gradle添加appcompat庫

dependencies {    
    compile 'com.android.support:appcompat-v7:X.X.X' // where X.X.X version  
}

2.Activity繼承android.support.v7.app.AppCompatActivity

public class MainActivity extends AppCompatActivity {  
    ...
}

3.styles.xml中設置按鈕樣式

<style name="MyButton" parent="Theme.AppCompat.Light">  
    <item name="colorControlHighlight">@color/indigo</item>
    <item name="colorButtonNormal">@color/pink</item>
</style>

4.爲Button設置theme

<Button    
    android:layout_width="wrap_content"  
    android:layout_height="wrap_content"  
    android:text="Button"  
    android:theme="@style/MyButton"/>

效果圖如下:

這裏寫圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章