Android中浮动按钮

冷不防 2022-06-06 04:21 327阅读 0赞

目的:
(1)设置按钮为浮动按钮
(2)设置为按下时颜色与按下时颜色


1.build.gradle添加appcompat库

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

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

  1. public class MainActivity extends AppCompatActivity {
  2. ...
  3. }

3.styles.xml中设置按钮样式

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

4.为Button设置theme

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

效果图如下:

这里写图片描述

发表评论

表情:
评论列表 (有 0 条评论,327人围观)

还没有评论,来说两句吧...

相关阅读