使用Xml的Android自定义类按钮

使用Xml的Android自定义类按钮,android,Android,在我的应用程序中,我想插入按钮(like按钮),但我想使用XML样式创建按钮 有什么想法吗?将其添加到xml中 <com.like.LikeButton app:icon_type="heart" app:icon_size="25dp" android:id="@+id/star_button" android:layout_width="wrap_content" android:layout_height="wrap_content"/> 将此添加到模块

在我的应用程序中,我想插入按钮(like按钮),但我想使用XML样式创建按钮

有什么想法吗?

将其添加到xml中

<com.like.LikeButton
  app:icon_type="heart"
  app:icon_size="25dp"
  android:id="@+id/star_button"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"/>
将此添加到模块的
build.gradle
文件:

dependencies {
    ...
    compile 'com.github.jd-alexander:LikeButton:0.2.3'
    }
}

您可以在这里找到教程

您可以在矢量资源中找到。竖起拇指图标

 <vector xmlns:android="http://schemas.android.com/apk/res/android"
            android:width="24dp"
            android:height="24dp"
            android:viewportWidth="24.0"
            android:viewportHeight="24.0">
        <path
            android:fillColor="#1B8FFB"
            android:pathData="M1,21h4L5,9L1,9v12zM23,10c0,-1.1 -0.9,-2 -2,-2h-6.31l0.95,-4.57 0.03,-0.32c0,-0.41 -0.17,-0.79 -0.44,-1.06L14.17,1 7.59,7.59C7.22,7.95 7,8.45 7,9v10c0,1.1 0.9,2 2,2h9c0.83,0 1.54,-0.5 1.84,-1.22l3.02,-7.05c0.09,-0.23 0.14,-0.47 0.14,-0.73v-1.91l-0.01,-0.01L23,10z"/>
 </vector>

然后用这种方式:

    <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/ic_thumb_up_black_24dp"
      />

使用
图像按钮
而不是
按钮

<ImageButton
    android:id="@+id/imageButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/icons8-Thumbs Up-48"
/>

您可以使用它,或访问以了解更多详细信息

类似的问题:提供一些示例代码为什么要创建自定义按钮?使用ImageButton代替按钮元素。简单易行。这里你能告诉我如何改变图像散射颜色吗
<ImageButton
    android:id="@+id/imageButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:srcCompat="@drawable/icons8-Thumbs Up-48"
/>