android textview 添加图标


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;
}
});
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值