Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中创建动态按钮?_Android - Fatal编程技术网

如何在android中创建动态按钮?

如何在android中创建动态按钮?,android,Android,我是android新手,有谁能告诉我如何创建一个按钮,就像附件中的图片一样,我可以点击星星,然后它会以另一个片段添加到我的收藏夹列表中 1)在drawables下创建向量drawable /res/drawable/ic_star.xml 2) 添加图像按钮 星形图像按钮 您是在寻找有关星形按钮的UI帮助,还是在收藏夹片段中显示喜爱卡片的代码?我正在寻找有关帮助的UI。我将尝试将答案发布在下面。答案发布在下面。如果有帮助,请告诉我 <vector xmlns:android="htt

我是android新手,有谁能告诉我如何创建一个按钮,就像附件中的图片一样,我可以点击星星,然后它会以另一个片段添加到我的收藏夹列表中

1)在drawables下创建向量drawable

/res/drawable/ic_star.xml


2) 添加图像按钮

星形图像按钮



您是在寻找有关星形按钮的UI帮助,还是在收藏夹片段中显示喜爱卡片的代码?我正在寻找有关帮助的UI。我将尝试将答案发布在下面。答案发布在下面。如果有帮助,请告诉我
<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="#F00000"
        android:pathData="M12,17.27L18.18,21l-1.64,-7.03L22,9.24l-7.19,-0.61L12,2 9.19,8.63 2,9.24l5.46,4.73L5.82,21z"/>
</vector>
<ImageButton 
        android:background="@android:color/transparent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_star"/>