美文网首页
SearchView自定义&ImageView判断是否默认

SearchView自定义&ImageView判断是否默认

作者: 流苏丶 | 来源:发表于2019-10-22 18:38 被阅读0次

SearchView自定义:

xml代码:
<androidx.appcompat.widget.SearchView
            android:id="@id/search_view"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:background="@drawable/search_view"
            app:queryHint="提示文字" />
Drawable中xml代码:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <!-- 填充 -->
    <solid android:color="@color/white" />
    <corners android:radius="5dp" />
</shape>

使用过程中发现Hint文字不显示,在代码中进行如下设置即可:

@BindView(R.id.search_view)
SearchView searchView;

searchView.setIconifiedByDefault(false);

其他:

@BindView(R.id.search_view)
SearchView searchView;
/**
 *取消搜索框的下划线
 */
searchView.findViewById(R.id.search_plate).setBackground(null);
searchView.findViewById(R.id.submit_area).setBackground(null);
/*
 *设置字体大小等
 */
EditText editText = searchView.findViewById(R.id.search_src_text);
editText.setTextSize(14);
editText.set……
//搜索框监听
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                //点击搜索执行逻辑
                ToastUtils.toast("执行搜索…");
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                //输入内容改变监听
                ToastUtils.toast("输入内容:"+newText);
                return false;
            }
        });
效果图

ImageView判断是否是默认图片:

/**
     * 判断当前的图片是不是和默认图片相同,可以用来判断用户是否选择了图片
     */
private boolean isImageEmpty() {
    Drawable.ConstantState dftState = ResourcesCompat.getDrawable(getResources(), R.drawable.default, null).getConstantState();
    Drawable.ConstantState state = imageView.getDrawable().getConstantState();
    return dftState.equals(state);
}

相关文章

网友评论

      本文标题:SearchView自定义&ImageView判断是否默认

      本文链接:https://www.haomeiwen.com/subject/jshcvctx.html