如何在android

时间:2015-06-20 18:32:20

标签: android background android-edittext shape

我正在为EditText创建一个背景形状 - xml如下:

<?xml version="1.0" encoding="UTF-8" ?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android">
  <solid android:color="@color/WhiteSmoke"/> 
  <stroke android:width="1dp" android:color="@color/aadhaar_logo_brown" />   
  <padding android:left="2dp" android:top="2dp" android:right="2dp" android:bottom="2dp" /> 
  <corners android:topRightRadius="10dp" />
  <gradient android:startColor="@color/White" 
            android:centerColor="@color/White" 
            android:endColor="@color/White"
            android:angle="0"/>
</shape>

但是我需要EditText右侧的图像来指示必填字段。我尝试以编程方式添加图像,但图像未显示在运行时

((EditText) findViewById(R.id.txt_enduser_name)).setCompoundDrawables(null, null, getResources().getDrawable(R.drawable.ic_mandatory_text_field), null);

请帮忙

1 个答案:

答案 0 :(得分:0)

您需要为形状提供“内在大小”:

onResume

然后,您可以将其设置为<shape xmlns:android="http://schemas.android.com/apk/res/android"> ... <size android:height="20dp" android:width="20dp"/> </shape>

drawableRight