![]() |
![]() |
![]() |
![]() |
|---|
Add maven jitpack.io and dependencies in build.gradle (Project) :
// build.gradle project
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
// build.gradle app/module
dependencies {
...
implementation 'com.google.android.material:material:1.2.1'
implementation 'com.github.gzeinnumer:SearchViewDialog:version'
implementation 'com.github.gzeinnumer:SimpleMaterialStyle:last-vesion'
//check on https://github.com/gzeinnumer/SimpleMaterialStyle
}- Material.io (docs)
- Multi and Single Selection in Recyclerview (docs) (example)
- DialogFragment (docs)
First Step. Use MaterialComponents in your style :
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
<style name="CustomDialogStyle" parent="Theme.MaterialComponents.Light.Dialog">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowMinWidthMajor">80%</item>
<item name="android:windowMinWidthMinor">80%</item>
<item name="android:windowEnterAnimation">@anim/anim_in</item>
<item name="android:windowExitAnimation">@anim/anim_out</item>
</style>Add This Line to res/color.xml. Important
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#6200EE</color>
<color name="colorPrimaryDark">#3700B3</color>
<color name="colorAccent">#03DAC5</color>
</resources>If you want to change default font, add custom_font.ttf to your res directory res->font.
Than add this style to your style.xml/themes.xml
<!-- Base application theme. -->
<!-- Change Base Font -->
<style name="Theme.MyLibsTesting" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<item name="android:fontFamily">@font/test_font</item>
</style>
<!-- Change TextView Font -->
<style name="BaseTextView">
<item name="android:fontFamily">@font/test_font</item>
</style>
<style name="BaseTextView.Bold" parent="BaseTextView">
<item name="android:fontFamily">@font/test_font</item>
</style>
<style name="BaseTextView.Italic" parent="BaseTextView">
<item name="android:fontFamily">@font/test_font</item>
</style>
<style name="BaseTextView.Bold.Italic" parent="BaseTextView">
<item name="android:fontFamily">@font/test_font</item>
</style>
<!-- Change Button Font -->
<style name="MyButtonText" parent="Widget.MaterialComponents.Button.TextButton">
<item name="android:fontFamily">@font/test_font</item>
</style>
<style name="MyButtonOutlined" parent="Widget.MaterialComponents.Button.OutlinedButton">
<item name="android:fontFamily">@font/test_font</item>
</style>
<style name="MyButtonContained">
<item name="android:fontFamily">@font/test_font</item>
</style>
<style name="MyButtonIcon" parent="Widget.MaterialComponents.Button.Icon">
<item name="android:fontFamily">@font/test_font</item>
</style>Dialog with 1 Title, 1 Content, 1 EditText, 1 RecyclerView, 1 Negative Button, 1 Positive Button. You can choise Single Item Select or Multi Item Select. The difference is only in callback function.
- Content Item there is 3 types data that you can sent to this dialog.
Type 1
String[] arrayString = {"M", "Fadli", "Zein"};
new SearchViewDialog<String>(getSupportFragmentManager())
.setItems(arrayString);Type 2
ArrayList<String> listString = new ArrayList<>();
listString.add("Lorem ipsum dolor");
new SearchViewDialog<String>(getSupportFragmentManager())
.setItems(listString);Type 3 for this type you should override function toString() in your model pojo
public class ExampleModel {
private int id;
private String name;
private String address;
//constructor
//getter
//setter
@Override
public String toString() {
return "ExampleModel{" +
"id=" + id +
", name='" + name + '\'' +
", address='" + address + '\'' +
'}';
}
}And dont forget to declare your model pojo after SearchViewDialog<ModelPojo>
ArrayList<ExampleModel> listObject = new ArrayList<>();
listObject.add(new ExampleModel(1, "Zein", "Balbar"));
new SearchViewDialog<ExampleModel>(getSupportFragmentManager())
.setItems(listObject);use your model pojo to callBack function. Example new SearchViewDialog.OnOkPressedSingle<ExampleModel>(){} or new SearchViewDialog.OnOkPressedMulti<ExampleModel>(){}
//For Single
new SearchViewDialog<ExampleModel>(getSupportFragmentManager())
.setItems(listObject)
.onOkPressedCallBackSingle(...);
//For Multi
new SearchViewDialog<ExampleModel>(getSupportFragmentManager())
.setItems(listObject)
.onOkPressedCallBackMulti(...);- Single Item Select. Use
onOkPressedCallBackSingleto enableSingle Select Item. Code :
ArrayList<String> list = new ArrayList<>();
list.add("Lorem ipsum dolor");
list.add("sit amet, consectetur");
list.add("adipiscing elit sed do");
new SearchViewDialog<String>(getSupportFragmentManager())
.setItems(list)
.setTitle("ini title")
.setContent("ini content")
.onOkPressedCallBackSingle(new SearchViewDialog.OnOkPressedSingle<String>() {
@Override
public void onOkSingle(String data) {
String temp = "Single Select : \n"+data.toString();
tv.setText(temp);
}
})
.onCancelPressedCallBack(new SearchViewDialog.OnCancelPressed() {
@Override
public void onCancelPressed() {
Toast.makeText(MainActivity.this, "Cancel", Toast.LENGTH_SHORT).show();
}
})
.show();- Multi Item Select. Use
onOkPressedCallBackMultito enableMulti Select Item. Code :
ArrayList<String> list = new ArrayList<>();
list.add("Lorem ipsum dolor");
list.add("sit amet, consectetur");
list.add("adipiscing elit sed do");
new SearchViewDialog<String>(getSupportFragmentManager())
.setItems(list)
.setTitle("ini title")
.setContent("ini content")
.onOkPressedCallBackMulti(new SearchViewDialog.OnOkPressedMulti<String>() {
@Override
public void onOkMulti(List<String> data) {
String temp = "Multi Select :\n";
temp = temp + "Total Data => "+data.size()+"\n\n";
for (String d: data){
temp = temp + "Value => "+ d +"\n";
}
tv.setText(temp);
}
})
.onCancelPressedCallBack(new SearchViewDialog.OnCancelPressed() {
@Override
public void onCancelPressed() {
Toast.makeText(MainActivity.this, "Cancel", Toast.LENGTH_SHORT).show();
}
})
.show();or you can write code like this :
SearchViewDialog dialog = new SearchViewDialog<String>(getSupportFragmentManager())
.setItems(list)
.setTitle("ini title")
.setContent("ini content");
dialog.onOkPressedCallBackMulti(new SearchViewDialog.OnOkPressedMulti<String>(){
@Override
public void onOkMulti(List<String> data) {
}
}).
dialog.onCancelPressedCallBack(new SearchViewDialog.OnCancelPressed<String>() {
@Override
public void onCancelPressed() {
Toast.makeText(MainActivity.this, "Cancel", Toast.LENGTH_SHORT).show();
}
});
dialog.show();Preview :
![]() |
![]() |
![]() |
|---|---|---|
Single Select Item Preview, you only can select 1 Item |
Click OK and call function onOkPressedCallBackSingle |
Fiture Filter will enable on Single Select or Multi Select |
![]() |
![]() |
|---|---|
Multi Select Item Preview, you can select more than 1 Item |
Click OK and call function onOkPressedCallBackMulti |
You can Customize your dialog UI. ReadMore.
FullCode MainActivity
- 2.0.3
- First Release
- 2.0.4
- Add animation and set custom animation show
- 2.0.5
- Bug Fixing
- 2.0.6
- Color
- 2.0.8
- Bug Fixing
- 2.0.9
- Bug Fixing
- 2.1.0
- Bug Fixing Color
- 2.1.1
- Bug Fixing Color
- 3.0.0
- Support SDK 16
- 3.0.1
- Bug Color
- 3.0.3
- Bug Fixing
- 3.0.4
- Bug Fixing
- 3.0.5
- Bug Fixing
- 3.0.6
- Bug Fixing
- 3.0.7
- Bug Fixing
- 3.0.7
- Fixing Space
- 3.1.0
- New Style
- 3.1.2
- Bug Fixing
- 3.1.3
- Custom Margin/Pading
- dimens.xml
- 3.1.4
- Enable Disable Filter
- 3.1.5
- Disable order on search
- 3.1.6
- Max length On Teks set to 30 and olny single line
You can sent your constibution to branch open-pull.
Copyright 2020 M. Fadli Zein






