EditText 背景颜色崩溃
EditText Backcolor crashes
谁能告诉我为什么这个简单的程序总是崩溃?
EditText editText1 = (EditText) findViewById(R.id.editText1);
View.OnClickListener onClickListener_button1 = new View.OnClickListener() {
@Override
public void onClick(View v) {
ColorDrawable drawable = (ColorDrawable)editText1.getBackground();
}
};
如评论中所述,您正在将 InsetBackground 转换为 ColorBackground,但失败了。
要获得正确的结果,您需要将 android:background="@color/initial_color"
设置为 xml 中的 EditText。
谁能告诉我为什么这个简单的程序总是崩溃?
EditText editText1 = (EditText) findViewById(R.id.editText1);
View.OnClickListener onClickListener_button1 = new View.OnClickListener() {
@Override
public void onClick(View v) {
ColorDrawable drawable = (ColorDrawable)editText1.getBackground();
}
};
如评论中所述,您正在将 InsetBackground 转换为 ColorBackground,但失败了。
要获得正确的结果,您需要将 android:background="@color/initial_color"
设置为 xml 中的 EditText。