Giter Club home page Giter Club logo

circular_switch_with_text's Introduction

Circular Switch with Text and Background

This library is used to make a circular bordered switch and changeable text and background, there are custom on click methods that switch background and text color automatically.

Screen Shot

Installation

Add it in your root build.gradle at the end of repositories:

maven { url 'https://jitpack.io' }

Add the dependency:

implementation 'com.github.ateebakhtar:Circular_Switch_with_Text:1.2.0'

Usage

Insert in the xml of your respective main file

 <com.ateeb.switchwithtext.CircularSwitch
        android:id="@+id/circle_center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        />

Use this is in your Kotlin file

val circularSwitch = findViewById<CircularSwitch>(R.id.circle_center)
circularSwitch.setOffButton("Post") {
     Toast.makeText(this, "Post", Toast.LENGTH_SHORT).show()
}
circularSwitch.setOnButton("Photos") {
     Toast.makeText(this, "Photos", Toast.LENGTH_SHORT).show()
}

Use this is in your Java file

CircularSwitch circularSwitch;
private void init() {
    circularSwitch = findViewById(R.id.circle_center);
    circularSwitch.setOnButton("On",openOn);
    circularSwitch.setOffButton("Off",openOff);
}

private View.OnClickListener openOn = new View.OnClickListener() {
    public void onClick(View v) {
        //todo add logic here
    }
};

private View.OnClickListener openOff = new View.OnClickListener() {
    public void onClick(View v) {
        //todo add logic here
    }
};

Additional Properties

Additional Properties in XML

app:activeButtonTextColor="@color/green"
app:positiveButtonTextColorForInactive="@color/black"
app:negativeButtonTextColorForInactive="@color/black"
app:setPositiveAsActive="false"

Additional Properties in Java

circularSwitch.setActiveButtonColor(ResourcesCompat.getColor(getResources(),R.color.grey,null));
circularSwitch.setInActiveNegativeButtonColor(ResourcesCompat.getColor(getResources(),R.color.grey,null));
circularSwitch.setInActivePositiveButtonColor(ResourcesCompat.getColor(getResources(),R.color.grey,null));
circularSwitch.setPostiveActive(false);

Additional Properties in Kotlin

circularSwitch.activeButtonColor = ResourcesCompat.getColor(resources, R.color.grey, null)
circularSwitch.inActiveNegativeButtonColor = ResourcesCompat.getColor(resources, R.color.grey, null)
circularSwitch.inActivePositiveButtonColor = ResourcesCompat.getColor(resources, R.color.grey, null)
circularSwitch.postiveActive = false

circular_switch_with_text's People

Contributors

ateebakhtar avatar

Stargazers

Noman Ali avatar  avatar Anosha Rehan avatar

Watchers

James Cloos 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.