Search-View-Layout

授权协议 Apache-2.0 License
开发语言 Java
所属分类 手机/移动开发、 Android UI 组件
软件类型 开源软件
地区 不详
投 递 者 钱弘壮
操作系统 Android
开源组织
适用人群 未知
 软件概览

THIS PROJECT IS DEPRECATED

Component is not maintained anymore.

Implementation of Lollipop+ Dialer and Google Maps.

DEMO

Add in View

Add to your layout by using the include tag.

<include layout="@layout/widget_search_bar"/>

API

This overlays the full activity and shows the fragment which you have assigned by using setExpandedContentFragment.

searchViewLayout.setExpandedContentFragment(this, new SearchStaticFragment());

If you want to animate your Toolbar too like the demo gif, you can enable it by using handleToolbarAnimation.

searchViewLayout.handleToolbarAnimation(toolbar);

Setting Background colors for Transition. Default should also work just fine:

// Create Drawable for collapsed state. Default color is android.R.color.transparent
ColorDrawable collapsed = new ColorDrawable(
    ContextCompat.getColor(this, R.color.colorPrimary));

// Create Drawable for expanded state. Default color is #F0F0F0
ColorDrawable expanded = new ColorDrawable(
    ContextCompat.getColor(this, R.color.default_color_expanded));

// Send both colors to searchViewLayout
searchViewLayout.setTransitionDrawables(collapsed, expanded);

Listen to search complete by:

searchViewLayout.setSearchListener(new SearchViewLayout.SearchListener() {
    @Override
    public void onFinished(String searchKeyword) {
        searchViewLayout.collapse();
        Snackbar.make(searchViewLayout, "Search Done - " + searchKeyword, Snackbar.LENGTH_LONG).show();
    }
});

Listen to collapse/expand animation by using setOnToggleAnimationListener. For eg the FAB in demo hides on expanded and shows on collapse.

searchViewLayout.setOnToggleAnimationListener(new SearchViewLayout.OnToggleAnimationListener() {
    @Override
    public void onStart(boolean expanded) {
        if(expanded) {
            fab.hide();
        } else {
            fab.show();
        }
    }

    @Override
    public void onFinish(boolean expanded) { }
});

Listen to search box complete by:

searchViewLayout.setSearchBoxListener(new SearchViewLayout.SearchBoxListener() {
    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    }
    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
    }
    @Override
    public void afterTextChanged(Editable s) {
    }
});

Setting Hints

If you want to set hints in the view, there are three APIs. setCollapsedHint would come up in the default/collapsed state. setExpandedHint would work for expanded state i.e. after click the view and the keyboard is up. setHint would set both the hints in one go, use this you want to show the same hint in both the states.

searchViewLayout.setCollapsedHint("Collapsed Hint");
searchViewLayout.setExpandedHint("Expanded Hint");
searchViewLayout.setHint("Global Hint");

Setting IconsUse setCollapsedIcon, setExpandedBackIcon, setExpandedSearchIcon to setup icons according to your choice. The argument should be a DrawableRes

NOTES

  1. If you want to add a scrolling widget in your setExpandedContentFragment, add a onTouchListener and disallow the parent intercept by usingv.getParent().requestDisallowInterceptTouchEvent(true);Check out fragments in sample for the implement of ListView, RecyclerView and ScrollView.

    recyclerView.setOnTouchListener(new View.OnTouchListener() {
        // Setting on Touch Listener for handling the touch inside ScrollView
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // Disallow the touch request for parent scroll on touch of child view
            v.getParent().requestDisallowInterceptTouchEvent(true);
            return false;
        }
    });
  2. The default height of the view is 120dp which is also present in the dimens.xml file as

    <dimen name="search_view_layout_approx_height">120dp</dimen>

    You can use it for adding margin on top of your main content layout.

GET

Available at jCenter and mavenCentral.

dependencies {
    compile 'xyz.sahildave:searchviewlayout:0.6'
}

CHANGELOG

0.6

  • Added support for API 15

0.5

  • Added support for fragment-v4

0.4

  • Moved anim files to /animator res dir

0.3

  • Added search edit text API
  • Larger touch target

0.2

  • Added APIs for setting icons
  • Improved animations by using onAnimationUpdate

0.1

  • Added hints API.
  • Added search_view_layout_approx_height

0.0.2

  • Added API setTransitionDrawables which solves crashes in < API 19

Contribute

Contribute by creating issues (tagged enhancement, bugs) in the repo or create a pull request.

  • 问题表现 在开发中遇到一个偶现的崩溃,日志堆栈如下: E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.edittextdemo, PID: 9528 java.lang.IllegalStateException: focus search returned a view that wasn't able t

  • 由于经常会使用  View view = inflater.inflate(R.layout.fragment_main, container, false); 或者 View view = inflater.inflate(R.layout.dialog_kp_user_product_item, null);   两个方法,但是不知道其有什么区别?如果搞错了会报     Caused by

  • 1、首先导包 [java]  view plain  copy  print ? compile 'com.android.support:design:26.1.0'   2、 使用NavigationView 首先在主布局文件中使用DrawerLayout作为外包装,里面包含一个主页面和侧滑的菜单页面,而侧滑菜单页面用NavigationView实现,drawerLayout中包含了主页面和侧

  • 最近项目开发时候遇到了这样一个问题,同样的布局内容,一个没问题另一个就报这个错误。 在网上搜索尝试了几个方法之后,最终得出结论。 重启Android Studio可以解决!

 相关资料
  • 1.接口描述 该API的功能是上传一张图片,返回图片搜索库中与该图片最相似的10张。 如果库中不足10张,则会返回全部图片。 图片要求 格式为 JPG(JPEG),BMP,PNG,GIF,TIFF 宽和高大于 8px,小于等于4000px 小于等于 5 MB 支持自动识别人脸方向 上传的图片中包含有 exif 方向信息,先按此信息旋转、翻转后再做识别人脸方向并调整。 如果照片方向混乱且 exif

  • Search Template 首先查看 Search Template 文档 /_search/template endpoint 允许我们在执行搜索请求和使用模板参数填充现有模板之前,能够使用 mustache 语言预先呈现搜索请求。 将模板参数定义为 Map <String,Object>: Map<String, Object> template_params = new HashMap<

  • Search Insert Position 描述 Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. You may assume no d

  • Search for a Range 描述 Given a sorted array of integers, find the starting and ending position of a given target value. Your algorithm's runtime complexity must be in the order of O(log n). If the targ

  • Search a 2D Matrix 描述 Write an efficient algorithm that searches for a value in an m × n matrix. This matrix has the following properties: Integers in each row are sorted from left to right. The first

  • search 方法 检索字符串中指定的子字符串或与正则表达式相匹配的子字符串。 语法: stringObject.search( sub_str ); stringObject.search( regexp ); 参数说明: sub_str/regexp - 要检索的子字符串或 RegExp 对象。( 要执行忽略大小写的检索 请追加标志 i ) 返回值: stringObject 中第一