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"/>
效果图如下:
还没有评论,来说两句吧...