我创建了一个drawable button_oval.xml
android:dither="true"
android:shape="rectangle">
android:width="3dp"
android:color="#29395e" />
android:width="300dp"
android:height="120dp" />
然后我在我的布局上使用它像这样:
// I want to add a icon inside this button
android:id="@+id/goToPersonalPage"
android:layout_width="110dp"
android:layout_height="50dp"
android:layout_marginLeft="30dp"
android:background="@drawable/button_oval"
android:text="@string/memberButton"
android:textColor="#29395e"
android:textSize="18dp" />
我想在Button中添加一个图标,是否有可能通过更改我的button_oval.xml来完成它?
最终输出应该如下图所示:
任何帮助将不胜感激.
解决方法:
你必须在你的Button元素中添加这些行 –
android:drawableLeft="@mipmap/ic_launcher_round" // to set an icon
android:drawablePadding="10dp" // to set the padding of icon from text
android:paddingLeft="20dp" // to set the padding of the icon and text
根据您的需要调整值.
它看起来像 –
标签:android,android-drawable,android-button,android-shape
来源: https://codeday.me/bug/20190717/1486927.html