Code Monkey home page Code Monkey logo

statebutton's Introduction

StateButton

###中文版这里: https://github.com/niniloveyou/StateButton/blob/master/README_CHINESE.md

Do you hate to write a background for each button?

Do you hate to write a bunch of selector?

That's why I'm writing this view.

Here to download demo

https://github.com/niniloveyou/StateButton/blob/master/demo.apk

Screenshot

Download

   allprojects {
       repositories {
           ......
           maven { url 'https://jitpack.io' }
       }
   }
   implementation 'com.github.niniloveyou:StateButton:v1.0.0'
   

Customizable attributes

Attribute default value xml java
normalTextColor original text color normalTextColor setNormalTextColor(int color)
pressedTextColor original text color pressedTextColor setPressedTextColor(int color)
unableTextColor original text color unableTextColor setUnableTextColor(int color)
strokeDashWidth 0 strokeDashWidth setStrokeDash(int dashWidth, int dashGap)
strokeDashGap 0 strokeDashGap setStrokeDash(int dashWidth, int dashGap)
normalStrokeWidth 0 normalStrokeWidth setNormalStrokeWidth(int widht)
pressedStrokeWidth 0 pressedStrokeWidth setPressedStrokeWidth(int widht)
unableStrokeWidth 0 unableStrokeWidth setUnableStrokeWidth(int widht)
normalStrokeColor 0 normalStrokeColor setNormalStrokeColor(int color)
pressedStrokeColor 0 pressedStrokeColor setPressedStrokeColor(int color)
unableStrokeColor 0 unableStrokeColor setUnableStrokeColor(int color)
normalBackgroundColor 0 normalBackgroundColor setNormalBackgroundColor(int color)
pressedBackgroundColor 0 pressedBackgroundColor setPressedBackgroundColor(int color)
unableBackgroundColor 0 unableBackgroundColor setUnableBackgroundColor(int color)
radius 0 radius setRadius(int radius) / setRadius(float[] radii)
round false round setRound(boolean round)
animationDuration 0ms animationDuration setAnimationDuration(int duration)

Usage

If the default values of custom attribues did not meet your requirement, you can easily re-config that attributes. This is sample code that you can refer. you can also browse demo app for more details.

via xml (sample)

  • Define xmlns:app="http://schemas.android.com/apk/res-auto" on root of your xml file
<deadline.statebutton.StateButton
            android:id="@+id/stateButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:text="StateButton"
            
            app:radius="5dp"
            app:round="true"
            app:animationDuration="200"
            
            app:strokeDashGap="2dp"
            app:strokeDashWidth="5dp"
            app:normalStrokeWidth="2dp"
            app:pressedStrokeWidth="2dp"
            app:unableStrokeWidth="2dp"
            
            app:normalStrokeColor="@android:color/white"
            app:pressedStrokeColor="@android:color/white"
            app:unableStrokeColor="@android:color/white"
            
            app:normalTextColor="@android:color/white"
            app:pressedTextColor="@android:color/white"
            app:unableTextColor="@android:color/white"
            
            app:normalBackgroundColor="@color/colorPrimaryDark"
            app:pressedBackgroundColor="@color/colorPrimaryDark"
            app:unableBackgroundColor="@color/colorPrimaryDark"/>

Developed By

deadline

Blog : http://www.jianshu.com/users/25e80ace21b8/latest_articles

MIT License

  Copyright (c) 2016 deadline

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:

  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.

statebutton's People

Contributors

mzlogin avatar niniloveyou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

statebutton's Issues

different_radius这个按钮有问题

different_radius这个按钮有问题,我粘贴这个different_radius Button ,显示的是一个矩形的Button,我想要的是两个是直角,两个是有5dp的弧度。

demo.apk

demo.apk 下载安装后闪退!!

太长了

使用android:layout_width="wrap_content"宽度没有自适应,而是默认了一个值,按钮只有两个文字的情况下,太长了,我暂时采取的做法是给一个默认值固定,但感觉不好,为什么android:layout_width="wrap_content"没有自适应呢?

setStateBackgroundColor方法内的pressed跟normal赋值反了

public void setStateBackgroundColor(@ColorInt int normal, @ColorInt int pressed, @ColorInt int unable){
mPressedBackgroundColor = normal;
mNormalBackgroundColor = pressed;
mUnableBackgroundColor = unable;
mNormalBackground.setColor(mNormalBackgroundColor);
mPressedBackground.setColor(mPressedBackgroundColor);
mUnableBackground.setColor(mUnableBackgroundColor);
}

按下去时的颜色有问题

在layout里面再设置一个background时,这个按下去的状态就有问题,这个按下去颜色会受到background的影响,具体原因不清楚。
我在activity theme设置了windowbackground,不设置layout的background就没问题

attr的参数冲突

C:\Users\37819.gradle\caches\transforms-2\files-2.1\a5652cf0840478a6de808e42c83293ab\jetified-StateButton-v1.0.0\res\values\values.xml:3:5-32:25: AAPT: error: duplicate value for resource 'attr/round' with config ''.

请教一下纯代码创建无效果问题

项目需要根据服务器传来的配置,来动态创建按钮,
我用以下方式来动态创建,但是没有效果
ll = findViewById(R.id.ll); //自定义 myradius = new StateButton(this); myradius.setRadius(50f); myradius.setWidth(200); myradius.setHeight(100); myradius.setPadding(10,10,10,10); myradius.setTextColor(Color.WHITE); myradius.setNormalBackgroundColor(R.color.colorPrimary); myradius.setPressedBackgroundColor(R.color.colorPrimaryDark); myradius.setText("myradius"); ll.addView(myradius);

请教一下要怎么写才有效果呢?
谢谢

太大了

按钮太大了,上下的间距太大了,
paddingTop , paddingBottom 这两个 设置没有用,
能不能像TextView那样,padding自己设置

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.