Android studio 花式按键

一、activity_main.xml代码:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:backgroundTint="#D8A91B"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/but1"
        android:layout_width="211dp"
        android:layout_height="60dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="32dp"
        android:layout_marginEnd="16dp"
        android:backgroundTint="#DAC82A"
        android:text="Button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/but2"
        android:layout_width="211dp"
        android:layout_height="60dp"
        android:layout_marginStart="32dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="32dp"
        android:background="@drawable/round_corner"

        android:text="圆角Button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/but1" />

    <Button
        android:id="@+id/but3"
        android:layout_width="211dp"
        android:layout_height="58dp"
        android:layout_marginStart="32dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="32dp"
        android:background="@drawable/stroke"
        android:text="描边 Button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/but2" />

    <Button
        android:id="@+id/but4"
        android:layout_width="211dp"
        android:layout_height="48dp"
        android:layout_marginStart="32dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="32dp"
        android:background="@drawable/press_effect"
        android:text="按压 Button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/but3" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="212dp"
        android:layout_height="60dp"
        android:layout_marginStart="32dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="32dp"
        android:gravity="center"
        android:text="Pattern buttons!"
        android:textColor="@color/red"
        android:textSize="16dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/but5" />

    <Button
        android:id="@+id/but5"
        android:layout_width="208dp"
        android:layout_height="48dp"
        android:layout_marginStart="32dp"
        android:layout_marginTop="16dp"
        android:layout_marginEnd="32dp"
        android:background="@drawable/gradient"
        android:text="Button"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/but4" />


</androidx.constraintlayout.widget.ConstraintLayout>

二、stroke.xml代码:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <corners android:radius="20dp" />

    <stroke
        android:width="2dp"
        android:color="#22DD22"
        />

</shape>

三、round_corner.xml代码:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <corners android:radius="20dp" />

    <solid android:color="#DC6D39" />

</shape>

四、press_effect.xml代码:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/clr_normal" android:state_pressed="false"/>
    <item android:drawable="@color/clr_pressed" android:state_pressed="true"/>
</selector>
五、运行效果:

六、工程项目:

Androidstudio花式按键设计资源-CSDN文库

相关推荐

  1. AndroidStudio

    2023-12-27 12:46:04       63 阅读
  2. AndroidStudio开发 相关依赖

    2023-12-27 12:46:04       44 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2023-12-27 12:46:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2023-12-27 12:46:04       100 阅读
  3. 在Django里面运行非项目文件

    2023-12-27 12:46:04       82 阅读
  4. Python语言-面向对象

    2023-12-27 12:46:04       91 阅读

热门阅读

  1. 如何强制 App 在 iOS 后台不断开与融云的长连接?

    2023-12-27 12:46:04       85 阅读
  2. 活动运营常用的ChatGPT通用提示词模板

    2023-12-27 12:46:04       58 阅读
  3. modbus-tcp-rtu协议图表

    2023-12-27 12:46:04       43 阅读
  4. leetcode | go | 第600题 | 不含连续1的非负整数

    2023-12-27 12:46:04       65 阅读
  5. vue中的动态组件和混入

    2023-12-27 12:46:04       51 阅读
  6. 2023年腾讯云活动:2核2G4M轻量服务器3年540元

    2023-12-27 12:46:04       63 阅读
  7. 分布式信号量(Redis)

    2023-12-27 12:46:04       56 阅读
  8. Spring缓存注解@Cacheable、@CachePut、@CacheEvict

    2023-12-27 12:46:04       58 阅读