是否可以为我们添加的android: drawablleft图像设置边缘或填充?
当前回答
如果可绘制资源的大小是固定的,你可以这样做:
<Button
android:background="@drawable/rounded_button_green"
style="?android:attr/selectableItemBackground"
android:layout_height="wrap_content"
app:layout_widthPercent="70%"
android:drawableRight="@drawable/ic_clear_black_24dp"
android:paddingRight="10dp"
android:paddingLeft="34dp"
tools:text="example" />
这里的关键是:
android:drawableRight="@drawable/ic_clear_black_24dp"
android:paddingRight="10dp"
android:paddingLeft="34dp"
也就是说,可绘制资源的大小加上paddingRight等于paddingLeft。
您可以在本例中看到结果
其他回答
而不是按钮使用LinearLayout与ImageView和TextView里面。在子项目,如ImageView和TextView使用android:duplicateParentState="true"。
是的。使用drawablePadding,如下所示
<TextView
android:id="@+id/tvHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Settings and Contents"
android:drawableLeft="@drawable/icon_success"
android:drawablePadding="10dp" />
android:drawablePadding是给可绘制图标填充最简单的方法,但你不能给特定的一侧填充,如paddingRight或paddingLeft的可绘制图标。要做到这一点,你必须深入研究。 如果你将paddingLeft或paddingRight应用到Edittext,那么它会将填充到整个Edittext以及可绘制的图标。
为你的编辑文本定义一个形状,并给它一个填充 例如
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<padding
android:left="5dp"
android:right="5dp"
/>
<solid android:color="#F6F6F6" />
<stroke
android:width="1px"
android:color="#C3C3C3" />
<corners
android:bottomLeftRadius="1dp"
android:bottomRightRadius="1dp"
android:topLeftRadius="1dp"
android:topRightRadius="1dp" />
</shape>
在此形状中定义的填充将帮助为可绘制的左侧或右侧提供填充 ---------------------- 应用这个EditView形状
<EditText
android:id="@+id/example"
android:layout_width="fill_parent"
android:layout_height="36dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/shape2"
android:drawableLeft="@drawable/icon1"
android:drawablePadding="@dimen/txtDrwblPadding"
android:ems="10"
/>
使用定义的形状作为背景将给你的EditText一些风格加上边框drawablleft。
textView.setCompoundDrawablesWithIntrinsicBounds(AppCompatResources.getDrawable(this,drawable),null,null,null);
addressTitleView.setCompoundDrawablePadding();
推荐文章
- 改变开关的“开”色
- 以编程方式将EditText的输入类型从PASSWORD更改为NORMAL,反之亦然
- 如何在隐藏和查看密码之间切换
- 在Android上调整一个大的位图文件到缩放输出文件
- 如何更改Android版本和代码版本号?
- Android Studio突然无法解析符号
- 应用程序重新启动而不是恢复
- 如何设置整个应用程序在纵向模式?
- Android中文本的阴影效果?
- 以编程方式设置TextView的布局权重
- Android -如何覆盖“后退”按钮,所以它不完成()我的活动?
- 如何从通知点击发送参数到一个活动?
- 导航目标xxx对于这个NavController是未知的
- 使用ConstraintLayout均匀间距的视图
- 文件google-services错误。模块根文件夹中缺少Json。谷歌服务插件没有它就不能正常工作。