1、xml
android:drawableRight="@drawable/refresh"
2、java
icon_ok = father.getResources().getDrawable(R.drawable.icon_ok);
icon_ok.setBounds(0, 0, icon_ok.getIntrinsicWidth(),
icon_ok.getIntrinsicHeight());
view.setCompoundDrawables(null, null, icon_ok, null);
或者Drawables
titleView.setCompoundDrawablesWithIntrinsicBounds(left, top, right, bottom);
或者 资源id
titleView.setCompoundDrawablesWithIntrinsicBounds(0, 0,
R.drawable.refresh, 0);
3、事件
// 触摸到搜索框的时候,判断是不是按到了搜索按钮
searchView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() != MotionEvent.ACTION_UP) {
return false;
}
if (event.getX() > searchView.getWidth()
- searchView.getPaddingRight() - icon_reflash.getIntrinsicWidth()) {
// 搜索
String key = searchView.getText().toString();
if (isNull(key)) {
return false;
}
NameValue item = new NameValue();
item.title = key;
item.type = "search";
item.value = key;
Comm.productListKey = item;
SearchManager sm = new SearchManager(SearchActivity.this);
sm.insert(key);
gotoActivity(ProductListActivity.class); // 跳转到搜索结果
}
return false;
}
});
android textview 添加图标
最新推荐文章于 2024-08-26 03:49:36 发布