Git-a custom iOS control ToggleSwitch
The previous custom controlToggleSwitch
:
At first glance, it looks like an old iOS Switch.
How to use?
Grade:
dependencies { compile 'us.belka:androidtoggleswitch:1.1.1'}
Maven:
us.belka
androidtoggleswitch
1.0
pom
Eclipse:
Just Copy the circled part.
How to Set it? (Take Eclipse Copy as an example)
The first effect is the added effect. If you need three, add custom: textToggleCenter = "default ".
If you have more? More than three?
You can get the control object in the business Activity and input an ArrayList.
Like this
ToggleSwitch toggleSwitch = (ToggleSwitch) findViewById(R.id.multiple_switches);ArrayList
labels = new ArrayList<>();labels.add("AND");labels.add("OR");labels.add("XOR");labels.add("NOT");labels.add("OFF");toggleSwitch.setLabels(labels);
The effect is as follows:
Because it does not inherit from the Switch, it does not have the so-called "true false2 return value" concept, all of which are returned by position, that is, from the leftmost-> the rightmost, increasing from 0 is the position of the clicked
So how to get the position?
ATo = (ToggleSwitch) findViewById (R. id. aTo); aTo. setOnToggleSwitchChangeListener (new ToggleSwitch. onToggleSwitchChangeListener () {@ Override public void onToggleSwitchChangeListener (int position) {Toast. makeText (MainActivity. this, position + "clicked", Toast. LENGTH_SHORT ). show ();}});
In this example, toast is implemented.
If you want to set a default item for initialization, set the position as follows:
toggleSwitch.setCheckedTogglePosition(position);
This is what you want to obtain.
int position = toggleSwitch.getCheckedTogglePosition();
Some settings are also listed below, mainly including the font size, color, and spacing.
Option Name |
Format |
Description |
Android: textSize |
dimension |
Text size of each button |
Custom: activeBgColor |
color |
Background color of the checked button |
Custom: activeTextColor |
color |
Text color of the checked button |
Custom: inactiveBgColor |
color |
Background color of the inactive buttons |
Custom: inactiveTextColor |
color |
Text color of the inactive buttons |
Custom: separatorColor |
color |
Color of the vertical separator between inactive buttons |
Custom: toggleWidth |
dimension |
Width of each button |
The general usage is the same as that of the source control, so there is no difference and the implementation is not very difficult. You can study it as appropriate, and you will be able to write your own pages.
Source Code address: https://github.com/BelkaLab/Android-Toggle-Switch/archive/master.zip