Skip to content

WavaSideBar+仿通讯录+字母导航栏+中英文搜索+拼音转换

Notifications You must be signed in to change notification settings

nanchen2251/WaveSideBar

Repository files navigation

WaveSideBar

WavaSideBar——一个自带中英文对应排序和检索功能的字母导航栏 ##效果图

⊙开源不易,希望给个star或者fork奖励

特点

1、支持手势滑动导航栏
2、支持自定义设置偏移量和颜色
3、支持设置字母导航栏设置位置
4、支持自动匹配中英文
5、支持拼音和中文搜索

使用方法

1、添加依赖

2017年1月5日后仓库转移到jitpack,添加依赖方式为:

Step 1. Add it in your root build.gradle at the end of repositories:
allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}
Step 2. Add the dependency
dependencies {
	        compile 'com.github.nanchen2251:WaveSideBar:1.0.6'
	}

2、在xml文件里面使用

  <!--搜索框-->
  <com.nanchen.wavesidebar.SearchEditText
        android:id="@+id/main_search"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginLeft="15dp"
        android:layout_marginRight="15dp"
        android:layout_marginTop="5dp"
        android:background="@drawable/search_edit_bg"
        android:drawableLeft="@mipmap/icon_search"
        android:drawablePadding="5dp"
        android:drawableStart="@mipmap/icon_search"
        android:gravity="center_vertical"
        android:hint="@string/search"
        android:imeOptions="actionSearch"
        android:maxLines="1"
        android:padding="5dp"
        android:textSize="16sp"
        app:drawableDel="@mipmap/edit_delete"/>
	
	
  <!--字母导航栏-->
  <com.nanchen.wavesidebar.WaveSideBarView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="8dp"
        android:id="@+id/main_side_bar"
        app:sidebar_text_color="@color/colorAccent"
        app:sidebar_lazy_respond="false"/>

3、在Activity里面使用

    mWaveSideBarView = (WaveSideBarView) findViewById(R.id.main_side_bar);
    mWaveSideBarView.setOnSelectIndexItemListener(new OnSelectIndexItemListener() {
        @Override
        public void onSelectIndexItem(String letter) {
            for (int i=0; i<mContactModels.size(); i++) {
                if (mContactModels.get(i).getIndex().equals(letter)) {
                    ((LinearLayoutManager) mRecyclerView.getLayoutManager()).scrollToPositionWithOffset(i, 0);
                    return;
                }
            }
        }
    });
    
    // 搜索按钮相关
        mSearchEditText = (SearchEditText) findViewById(R.id.main_search);
        mSearchEditText.addTextChangedListener(new TextWatcher() {
            @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) {
	        //You can do something in there
                mShowModels.clear();
                for (ContactModel model : mContactModels) {
                    String str = Trans2PinYinUtil.trans2PinYin(model.getName());
                    if (str.contains(s.toString())|| model.getName().contains(s.toString())) {
                        mShowModels.add(model);
                    }
                }
                mAdapter.notifyDataSetChanged();
            }
        });

4、自动匹配中英文

FirstLetterUtil.getFirstLetter(name);

5、中文转换成拼音

Trans2PinYinUtil.trans2PinYin(String name);

具体请下载查看示例代码

属性一览

Attributes Format Default Description
sidebar_text_color color Color.GRAY Text color.
sidebar_max_offset dimension 80dp Offset of the selected item.
sidebar_position enum {right, left} right Be placed on left or right in the view.
sidebar_text_alignment enum {center, left, right} center Alignment of items.
sidebar_lazy_respond boolean false If true, the listener will not be called until the finger up. If false, the listener will be called when the finger down, move and up.

该项目参考了:

关于作者

   南尘
   四川成都
   其它开源
   博客园

Licenses

 Copyright 2019 nanchen(刘世麟)

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.

About

WavaSideBar+仿通讯录+字母导航栏+中英文搜索+拼音转换

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages