美文网首页Android技术知识Android知识Android开发
一个支持渐变背景、圆角、阴影的Button

一个支持渐变背景、圆角、阴影的Button

作者: 搬砖人 | 来源:发表于2017-10-22 09:19 被阅读0次

预览:

device-2017-10-22-090603.png

Github

https://github.com/duweigang/GradientButton
注:为了防止以后有需求,可以star一下( ⊙ o ⊙ )!

Gradle

dependencies {
    compile 'com.dagang:gradient-button:1.0.1'
}

使用

<com.dagang.library.GradientButton
        android:layout_width="200dp"
        android:layout_height="80dp"
        app:button_end_color="#EEA9B8"
        app:button_gradient_orientation="LEFT_RIGHT"
        app:button_is_shadowed="true"
        app:button_press_end_color="#EEE5DE"
        app:button_press_start_color="#EEA9B8"
        app:button_radius="30dp"
        app:button_shadow_angle="90"
        app:button_shadow_color="#EE799F"
        app:button_shadow_distance="5dp"
        app:button_shadow_radius="10dp"
        app:button_size="10sp"
        app:button_start_color="#EEE5DE"
        app:button_text="Rich Button"
        app:button_text_color="#9F79EE" />

动态代码修改

GradientButton gradientButton = (GradientButton) findViewById(R.id.magic_button);
        TextView textView = gradientButton.getButton();
        textView.setText("Custom Button");
        textView.setTextColor(Color.BLUE);
        gradientButton.setButtonRadius(20);
        gradientButton.setShadowRadius(10);
        gradientButton.setShadowColor(Color.RED);
        gradientButton.setButtonStartColor(Color.parseColor("#EEE5DE"));
        gradientButton.setButtonEndColor(Color.parseColor("#9370DB"));
        gradientButton.setButtonPressStartColor(Color.BLACK);
        gradientButton.setButtonPressEndColor(Color.BLACK);
        gradientButton.setButtonGradientOrientation(GradientButton.LEFT_RIGHT);
        gradientButton.getButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this, "onClick", Toast.LENGTH_LONG).show();
            }
        });

相关文章

网友评论

    本文标题:一个支持渐变背景、圆角、阴影的Button

    本文链接:https://www.haomeiwen.com/subject/sahguxtx.html