Git-a custom iOS control ToggleSwitch

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.