An android library that mimics the functionality of a Radio Group and provides a custom layout for option selections.
-
Just add dependencies in
- Project level gradle:
allprojects { repositories { . . . maven { url 'https://jitpack.io' } . . } }
- And app level gradle:
dependencies { . . . implementation 'com.github.yashprakash13:MultiChoiceLinearLayout:1.1' . . }
and you are good to go!
<tech.pcreate.multichoicelayout.MultiChoiceLayout
android:id="@+id/multichoices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
app:backType="stroke"
app:backStrokeWidth="3"
app:backgroundColor="@color/colorPrimaryDark"
app:opt1="@string/monthly"
app:opt1TColor="@color/white"
app:opt2="@string/yearly"
app:opt2TColor="@color/white"
app:ignoreThird="true"
app:ignoreFourth="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/appBarLayout"
app:selectedOptionBackground="@color/white_depth">
</tech.pcreate.multichoicelayout.MultiChoiceLayout>
- Simply remove
<tech.pcreate.multichoicelayout.MultiChoiceLayout
.
.
.
app:ignoreThird="true"
</tech.pcreate.multichoicelayout.MultiChoiceLayout>
- and add:
<tech.pcreate.multichoicelayout.MultiChoiceLayout
.
.
.
app:opt3="@string/yourString"
app:opt3TColor="@color/yourColor"
</tech.pcreate.multichoicelayout.MultiChoiceLayout>
- Remove:
<tech.pcreate.multichoicelayout.MultiChoiceLayout
.
.
.
app:ignoreThird="true"
app:ignoreFourth="true"
</tech.pcreate.multichoicelayout.MultiChoiceLayout>
- and add:
<tech.pcreate.multichoicelayout.MultiChoiceLayout
.
.
.
app:opt3="@string/yourString"
app:opt3TColor="@color/yourColor"
app:opt4="@string/yourString"
app:opt4TColor="@color/yourColor"
</tech.pcreate.multichoicelayout.MultiChoiceLayout>
- Add this line to your Activity/Fragment:
MultiChoiceLayout multiChoiceLayout = findViewById(R.id.multichoices);
multiChoiceLayout.setOnClickListener(this);
- and implement this Interface:
public class MyActivity implements MultiChoiceLayout.MultiChoiceOnclick {
. . .
- Then, get the click action like this:
@Override
public void onMultiChoiceLayoutClick() {
if(MultiChoiceLayout.getSelection() == 1){
// Do some work
}
else if(MultiChoiceLayout.getSelection() == 2){
// Do some work
}
...
//so on
}
// For setting three choices use:
multiChoiceLayout.setOptionText(option1, option2, option3, null);
// And add fourth option as the ignore attribute:
multiChoiceLayout.setIgnoreChoices(false, false, true);
Likewise for Two choices, one choice or all four choices.
//Background of the layout can be either solid or stroke :
multiChoiceLayout.setBackground(R.color.color_1, 4, MultiChoiceLayout.STROKE); // Use for solid background : MultiChoiceLayout.SOLID, width parameter will be ignored.
// Selected Option Background color:
multiChoiceLayout.setSelectedBackgroundColor(R.color.color_1);
// Option Text color:
multiChoiceLayout.setOptionTextColor(R.color.color_1);