EditText中插入图片(3)
setContentView(R.layout.main);
init();
}
private void init(){
mEditText=(EditText) findViewById(R.id.editText);
mButton=(Button) findViewById(R.id.button);
mButton.setOnClickListener(new ClickListenerImpl());
}
private class ClickListenerImpl implements OnClickListener {
@Override
public void onClick(View v) {
ImageSpan imageSpan = new ImageSpan(MainActivity.this,
BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher));
SpannableString spannableString = new SpannableString("test");
spannableString.setSpan(imageSpan, 0, spannableString.length(),SpannableString.SPAN_MARK_MARK);
mEditText.append(spannableString);
}
}
}
package com.cn;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.style.ImageSpan;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.app.Activity;
import android.graphics.BitmapFactory;
/**
* Demo描述:
* 往EditText中插入图片
*/
public class MainActivity extends Activity {
private EditText mEditText;
private Button mButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
}
private void init(){
mEditText=(EditText) findViewById(R.id.editText);
mButton=(Button) findViewById(R.id.button);
mButton.setOnClickListener(new ClickListenerImpl());
}
private class ClickListenerImpl implements OnClickListener {
@Override
public void onClick(View v) {
ImageSpan imageSpan = new ImageSpan(MainActivity.this,
BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher));
相关新闻>>
- 发表评论
-
- 最新评论 更多>>