Android中浮动按钮

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_33833327/article/details/78391853

目的:
(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"/>

效果图如下:

这里写图片描述

猜你喜欢

转载自blog.csdn.net/qq_33833327/article/details/78391853