Android Material Design按钮样式设计

Today we’ll dive deep into Android Buttons in Material Design and develop an application that showcases the different styles of a Button.

今天,我们将深入研究Material Design中的Android Buttons,并开发一个应用程序来展示Button的不同样式。

Android Material Design按钮 (Android Material Design Button)

Buttons in Android are used to communicate our actions with the application. The introduction of Material Design has brought along many different kinds of Button styles which are compatible with pre-Lollipop devices too.

Android中的按钮用于与应用程序交流我们的操作。 Material Design的引入带来了许多不同类型的Button样式,它们也与之前的Lollipop设备兼容。

A basic Button in the layout is defined like this:

布局中的基本Button定义如下:

<LinearLayout xmlns:android="https://schemas.android.com/apk/res/android"
    xmlns:tools="https://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center"
    tools:context="com.journaldev.androidbuttonstyling.MainActivity">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="NORMAL BUTTON"/>

</LinearLayout>

The above Button has the default style: Widget.AppCompat.Button

上面的Button具有默认样式: Widget.AppCompat.Button

To set a different style on the Button, we use the android:background attribute.

要在Button上设置其他样式,我们使用android:background属性。

<Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:textColor="@android:color/white"
        android:layout_margin="12dp"
        android:text="BACKGROUND COLOR BUTTON"/>

The output of both of the above Buttons looks like this:

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值