我想要做的是将图像绘制到AutoCompleteTextView小部件中。
经过一些研究后: http://www.droidnova.com/playing-with-graphics-in-android-part-i,147.html 和 http://developer.android.com/resources/samples/NotePad/src/com/example/android/notepad/NoteEditor.html我把以下课程放在一起......
public class myAutoCompleteTextView extends AutoCompleteTextView
{
//member variables
private Rect mRect;
private Paint mPaint;
/**
* Constructors used by LayoutInflater
*/
public myAutoCompleteTextView(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
mRect = new Rect();
mPaint = new Paint();
}
public myAutoCompleteTextView(Context context, AttributeSet attrs)
{
super(context, attrs);
mRect = new Rect();
mPaint = new Paint();
}
public myAutoCompleteTextView(Context context)
{
super(context);
mRect = new Rect();
mPaint = new Paint();
}
@Override
protected void onDraw(Canvas canvas)
{
Bitmap _scratch = BitmapFactory.decodeResource(getResources(), R.drawable.search);
//canvas.drawBitmap(_scratch, 0.0f, 0.0f, mPaint);
canvas.drawBitmap(_scratch, 0.0f, 0.0f, null);
// Finishes up by calling the parent method
super.onDraw(canvas);
//this.invalidate();
}
}
和XML布局......
<com.test.customcontrols.myAutoCompleteTextView
android:id="@+id/myautocomplete"
android:layout_width="200dip"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:gravity="center_horizontal"
android:layout_gravity="center_horizontal"
android:inputType="textCapWords|textNoSuggestions|textVisiblePassword"/>
不幸的是,AutoCompleteTextView看起来似乎没有动过。 如何将我的图像合并到小部件的常用背景上,我该怎么办?
答案 0 :(得分:0)
制作自定义组件需要进行一些详细的研究......与此同时我解决了它:
AutoCompleteTextView mAutoCompleteTextView;
mAutoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.myautocomplete);
mAutoCompleteTextView.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.myimage), null, null, null);