實例:
package com.AndroidEditText;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class AndroidEditTextActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText input = (EditText)findViewById(R.id.input);
Button buttonClear = (Button)findViewById(R.id.clear);
buttonClear.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
input.setText("");
}});
Drawable icon = getResources().getDrawable(R.drawable.icon);
input.setCompoundDrawablesWithIntrinsicBounds(
icon, //left
icon, //top
icon, //right
icon); //bottom
}
}
相關文章:
- 通過XML在編輯文本(EditText)旁邊放置圖標
沒有留言:
發佈留言