gpt4 book ai didi

android - 带有图标和文本的按钮

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:12:58 25 4
gpt4 key购买 nike

我想在 Android 中制作一个 Button :

Connexion button

但我不知道该怎么做。我是否必须对某些元素(ImageViewTextView、分隔符...)使用 RelativeLayout

我真的不知道最佳做法。

最佳答案

You can use Button with Property android:drawableLeft="@drawable/ic_done".

引用这个。

 <Button
android:id="@+id/button111111"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="5dp"
android:layout_centerHorizontal="true"
android:drawableLeft="@drawable/ic_done"
android:text="Facebook" />

编辑 1:

If you want to do it without using Button with Property android:drawableLeft="@drawable/ic_done" Then.

引用这个。

res -> drawable 文件夹中创建名为 Shape.xmlXML 文件。

如果在 res 目录中没有看到 drawable 文件夹,则创建名为 drawable 的文件夹。

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke
android:width="3dip"
android:color="@android:color/black" />
<corners android:radius="10dip" />
<padding
android:bottom="10dip"
android:left="10dip"
android:right="10dip"
android:top="10dip" />
</shape>

然后引用这个Layout。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape"
android:gravity="center_vertical">


<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/app_name"
android:src="@mipmap/ic_launcher" />

<View
android:layout_width="2dp"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:background="@android:color/darker_gray" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:background="@null"
android:text="Submit" />


</LinearLayout>

这是屏幕。

enter image description here

注意:根据您的选择更改您的DrawableColor

关于android - 带有图标和文本的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37113498/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com