我有一个带有提示的微调器。是否可以将提示作为图像?我需要CustomArrayAdapter
吗?
这是我的ArrayAdapter
:
Spinner legalSpinner = (Spinner) findViewById(R.id.legal);
legal = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item,android.R.id.text1);
legalSpinner.setPrompt("Places");
legal.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
legalSpinner.setAdapter(legal);
任何帮助将不胜感激!
答案 0 :(得分:0)
好的,经过几天的工作,我设法自己解决了这个问题。如果要将微调器提示设置为图像,则必须使用ImageGetter
。
legalSpinner.setPrompt(Html.fromHtml("<img src=\"image\"", new Html.ImageGetter() {
@Override
public Drawable getDrawable(String s) {
Drawable drawFromPath;
int path =
MyClass.this.getResources().getIdentifier(s, "drawable",
getBaseContext().getPackageName());
drawFromPath = (Drawable) MyClass.this.getResources().getDrawable(path);
drawFromPath.setBounds(0, 0, drawFromPath.getIntrinsicWidth(),
drawFromPath.getIntrinsicHeight());
return drawFromPath;
}
}