因为我用的是
EditText et=new EditText(this);
locationEditText.setBackgroundDrawable(et.getBackground());但是setBackgroundDrawable(Drwable)在API16中被弃用,因为它不能使用setBackground(Drwable),因为它是在API16中添加的,我正在使用比它更早的版本
所以我只剩下两个函数了
分别是:setBackgroundColor(int color)和setBackgroundResource(int resid)
那么如何将其设置为全息光主题中的默认EditText呢?
发布于 2013-08-07 18:13:02
使用与setBackgroundDrawable(Drwable)功能相同的setBackground(Drawable drawable)。
编辑: thx到此代码(source)的Warpzit
EditText et=new EditText(this);
int sdk = android.os.Build.VERSION.SDK_INT;
if(sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
setBackgroundDrawable(et.getBackground());
} else {
setBackground(et.getBackground());
}你可以找到更多信息in this question
发布于 2013-08-07 18:54:46
这可能会对你有帮助
<EditText
android:layout_height="wrap_content"
android:layout_width="wrap_content"
style="@android:style/Widget.Holo.EditText"/>发布于 2015-12-16 20:00:42
我的建议是为edittext创建一个具有您需要分配的样式的模板布局xml文件,并在代码中需要时对其进行膨胀。在XML中
在代码中使用以下代码:
空)getLayoutInflater().inflate(R.layout.edtemplate,et =(
EditText EditText);
请访问android set style in code了解更多信息
https://stackoverflow.com/questions/18100475
复制相似问题