2011-05-27 83 views
0

我想要做的是将图像绘制到AutoCompleteTextView小部件中。无法将我的图像绘制到扩展小部件中

在经过一番研究: http://www.droidnova.com/playing-with-graphics-in-android-part-i,147.htmlhttp://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

我想你必须覆盖dispatchDraw() – ingsaurabh 2011-05-27 04:50:25

回答

0

制作自定义组件将采取一些细致的研究......在此期间,我解决了它:

AutoCompleteTextView mAutoCompleteTextView; 
mAutoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.myautocomplete); 
mAutoCompleteTextView.setCompoundDrawablesWithIntrinsicBounds(getResources().getDrawable(R.drawable.myimage), null, null, null);