您当前的位置: 首页 > 

RMSwitch

发布时间:2016-10-20 09:19:33 ,浏览量:0

RMSwitch
项目地址: RiccardoMoro/RMSwitch
简介:A simple and customizable Switch View

A simple View that works like a switch, but with more customizations.  With the option to choose between two or three states. (from v1.1.0)

[Changelog] (CHANGELOG.md)

Download Gradle:
compile 'com.rm:rmswitch:1.1.1'
Usage

To use them, just add this to your layout file

    

                    
    

... if you need to use this View's custom xml attributes (shown in a table below) do not forget to add this to your root layout

xmlns:app="http://schemas.android.com/apk/res-auto"

To see how it looks in the preview screen of Android Studio, build your project first

And this in your Activity

public class MainActivity extends AppCompatActivity {
    RMSwitch mSwitch;
    RMTristateSwitch mTristateSwitch;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mSwitch = (RMSwitch) findViewById(R.id.your_id);
        mTristateSwitch = (RMTristateSwitch) findViewById(R.id.your_id2);

        // Add a Switch state observer
        mSwitch.addSwitchObserver(new RMSwitch.RMSwitchObserver() {
            @Override
            public void onCheckStateChange(boolean isChecked) {
                                Toast.makeText(MainActivity.this, 
                                        "Switch state: " + 
                                        (isChecked ? "checked" : "not checked"), Toast.LENGTH_LONG)
                                        .show();
            }
        });

        mTristateSwitch.addSwitchObserver(new RMTristateSwitch.RMTristateSwitchObserver() {
            @Override
            public void onCheckStateChange(@RMTristateSwitch.State int state) {
                Toast
                        .makeText(MainActivity.this,
                                state == RMTristateSwitch.STATE_LEFT ?
                                        "Left" :
                                        state == RMTristateSwitch.STATE_MIDDLE ?
                                                "Middle" :
                                                "Right",
                                Toast.LENGTH_SHORT).show();
            }
        });
    }
}
关注
打赏
1688896170
查看更多评论

暂无认证

  • 0浏览

    0关注

    111319博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文
立即登录/注册

微信扫码登录

0.0820s