修改SearchView搜索框的背景线.(或着其他属性)

今天是来移动的第二天,雨好大...


项目经理让我修改一下android4.2.2日历中的SearchView.

要求去掉当SearchView得到焦点时候出现的蓝色背景线.

怎么说呢,很苦恼,基本没看过源码.而且android studio用的还不是太溜,电脑也卡才4G


虽然基本上一天等虚拟机就得有百分之八十的时间,但是庆幸还是弄出来了.代码如下:


SearchView calSearchView = (SearchView)v.findViewById(R.id.calendar_search_view);
if (calSearchView != null) {
    try {
        //--拿到字节码
        Class<?> argClass = calSearchView.getClass();
        //--指定某个私有属性,mSearchPlate是搜索框父布局的名字
        Field ownField = argClass.getDeclaredField("mSearchPlate");
        //--暴力反射,只有暴力反射才能拿到私有属性
        ownField.setAccessible(true);
        View mView = (View) ownField.get(calSearchView);
	//--设置背景 
mView.setBackgroundColor(Color.TRANSPARENT); } catch (Exception e) { e.printStackTrace(); }}


好了.马上下班了.



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值