Git Product home page Git Product logo

switchbutton's Introduction

SwitchButton

仿IOS风格的开关,简洁易懂,只有一个类文件。

先看下效果

Aaron Swartz

如何添加控件到项目

1:下载此项目,拿到SwitchButton这个类,复制到你的项目中。然后把自定义属性添加到你的attrs文件中

Aaron Swartz

2:在你的布局文件中添加

                <com.xie.brad.myswitchbutton.MyButton.SwitchButton
                android:id="@+id/switchbutton"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                app:switch_state="true"/>

switch_state 设置按钮的开关状态。

3:设置回调

      package com.xie.brad.myswitchbutton;
      import android.os.Bundle;
      import android.support.v7.app.AppCompatActivity;
      import android.widget.Toast;
      import com.xie.brad.myswitchbutton.MyButton.SwitchButton;
      public class MainActivity extends AppCompatActivity implements SwitchButton.OnSwitchListener {

          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
              SwitchButton switchButton = (SwitchButton) findViewById(R.id.switchbutton);
              switchButton.setOnSwitchListener(this);//设置button的点击回调
          }

          @Override
          public void openbutton() {
              Toast.makeText(this,"开",Toast.LENGTH_SHORT).show();
          }

          @Override
          public void closebutton() {
              Toast.makeText(this,"关",Toast.LENGTH_SHORT).show();
          }
      }

4:如何调整控件的高度?

Aaron Swartz

switchbutton's People

Contributors

xiebinjava avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.