【问题标题】:I want to make my Searchview similar to this我想让我的 Searchview 与此类似
【发布时间】:2016-11-09 12:46:52
【问题描述】:

我有一个像第二个一样的搜索视图,我想让它像第一个一样,但我不知道如何

【问题讨论】:

  • 你到底想要什么?灰色下划线?灰色关闭按钮?
  • 不,蓝色下划线。

标签: android searchview


【解决方案1】:

1 首先在水平布局中创建编辑文本和图像视图。

2 使图像视图可见为假。会有2张图片true_image和false_image,根据编辑文本值改变图片查看图片。

3 编辑文本的方法如下:

edittext.addTextChangedListener(new TextWatcher() {

 @Override
 public void onTextChanged(CharSequence s, int start, int before, int count) {
 // TODO Auto-generated method stub

 Value = edittext.getText().toString();

   if(Your Condition){
      imageview.setimage(R.Drawable.true_image);
   }else{
       imageview.setimage(R.Drawable.false_image);
   }

 }

 @Override
 public void beforeTextChanged(CharSequence s, int start, int count,
 int after) {
 // TODO Auto-generated method stub

 }

 @Override
 public void afterTextChanged(Editable s) {
 // TODO Auto-generated method stub

 }
 });
 }

希望这个答案对你有所帮助。

【讨论】:

    【解决方案2】:

    您可以使用此代码自定义默认搜索视图

    @Override
    public boolean onCreateOptionsMenu(final Menu menu) {
    
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.xyz, menu);
    
        MenuItem searchItem = menu.findItem(R.id.action_search);
    
        if (searchItem != null) {
    
            SearchView searchView = (SearchView) searchItem.getActionView();
    
            if (searchView != null) {
    
                // Full view of search
                View searchPlate = searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
    
                // Apply customisation as you want
                ImageView searchClose =(ImageView) searchView.findViewById(android.support.v7.appcompat.R.id.search_close_btn);
    
                // Edittext of search view so you can customize this also
                EditText searchSourceText = (EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);  
            }
    
        }
    
    }
    

    【讨论】:

      【解决方案3】:

      改变下划线颜色:

      View searchplate =searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
          searchplate.getBackground().setColorFilter(Color.BLUE, PorterDuff.Mode.MULTIPLY);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-09-25
        • 1970-01-01
        • 2010-09-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多