简体   繁体   English

具有图像和文本的自定义切换按钮

[英]custom toggle button with image and text

I want to create a toggle button with image on the left of the text. 我想创建一个切换按钮,并在文字左侧添加图片。 I use this code to make the image on the left: 我使用以下代码将图像显示在左侧:

 <ToggleButton
            android:textOn="Like"
            android:textOff="Liked"
            android:drawableLeft="@drawable/tggle_btn_like"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="false"
           />

However the image is too big. 但是,图像太大。 If I set the layout_width and layout_height to a value, the image doens't scale accordingly. 如果将layout_width和layout_height设置为一个值,则图像不会相应缩放。 My question is how to set with and height for the left drawable of a toggle. 我的问题是如何为切换的左侧可绘制对象设置高度和高度。

在此处输入图片说明

I want to make it like this 我要这样

在此处输入图片说明

You can set a padding 您可以设置填充

paddingRight or paddingLeft paddingRight或paddingLeft

android:paddingLeft="5dp"
android:paddingTop="3dp"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM