【发布时间】:2013-11-11 10:42:54
【问题描述】:
我使用了this 示例并尝试像editText.setBackgroundResource(R.drawable.edit_text_back); 一样以编程方式将其添加到我的编辑文本中,但它不起作用。我怎样才能做到这一点?有什么建议或想法吗?
EDIT editText 也是以编程方式定义的。
EditText editText = new EditText(this.getApplicationContext());
我将此添加到表格行中
尝试过
editText.setBackground(getResources().getDrawable(R.drawable.edit_text_back));
editText.setBackgroundDrawable(getResources().getDrawable(R.drawable.edit_text_back));
编辑文本创建
TableRow row = (TableRow) findViewById(R.id.table_row_kind);
TableRow.LayoutParams rowP = new TableRow.LayoutParams();
rowP.setMargins(10, 0, 0, 0);
editText = new EditText(this.getApplicationContext());
editText .setGravity(Gravity.FILL_HORIZONTAL);
editText .setLayoutParams(rowP);
editText .setFilters(new InputFilter[]{txtFilter});
editText.setBackground(getResources().getDrawable(R.drawable.edit_text_back));
行.xml
<TableRow
android:id="@+id/table_row_kind"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip" >
<TextView
android:layout_width="250sp"
android:text="Kind"
android:textAppearance="?android:attr/textAppearanceLarge" />
</TableRow>
【问题讨论】:
-
editText.setBackgroundDrawable(getResources().getDrawable(R.drawable.edit_text_back));试试这个@Lunchbox
-
我认为这个帖子可能会对你有所帮助。 stackoverflow.com/questions/3496269/…
-
您链接的示例SO问题解释得非常丰富..
-
@BojanJovanovic 我尝试了你的答案,但仍然没有结果,我没有扩展 TextView,而是扩展了 EditText。不过谢谢
-
@Indiandroid 我试过但没用,请看我的编辑
标签: android android-edittext background-color