Android 发现一个炫酷按钮库(ShineButton)

1.直接看效果图吧:
这里写图片描述
下面是使用方法:
2.添加依赖

    compile 'com.sackcentury:shinebutton:0.1.6'
    compile 'com.jakewharton:butterknife:8.4.0'
    compile 'com.jakewharton:butterknife-compiler:8.4.0'

3.Mainactivity

package com.example.geekp.shinebuttondemo;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;

import com.sackcentury.shinebuttonlib.ShineButton;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity {

    String TAG = "MainActivity";
    @BindView(R.id.po_image0)
    ShineButton shineButton;
    @BindView(R.id.po_image1)
    ShineButton porterShapeImageView1;
    @BindView(R.id.po_image2)
    ShineButton porterShapeImageView2;
    @BindView(R.id.po_image3)
    ShineButton porterShapeImageView3;
    @BindView(R.id.wrapper)
    LinearLayout linearLayout;

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

        if (shineButton != null)
            shineButton.init(this);
        if (porterShapeImageView1 != null)
            porterShapeImageView1.init(this);
        if (porterShapeImageView2 != null)
            porterShapeImageView2.init(this);
        if (porterShapeImageView3 != null)
            porterShapeImageView3.init(this);
        porterShapeImageView3.setShineTurnAngle(1);
        //在java代码中动态添加按钮
       /* ShineButton shineButtonJava = new ShineButton(this);

        shineButtonJava.setBtnColor(Color.GRAY);
        shineButtonJava.setBtnFillColor(Color.RED);
        shineButtonJava.setShapeResource(R.raw.like);
        shineButtonJava.setAllowRandomColor(false);
        shineButtonJava.setShineSize(100);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(100, 100);
        shineButtonJava.setLayoutParams(layoutParams);
        if (linearLayout != null) {
            linearLayout.addView(shineButtonJava);
        }*/
        //监听事件
        shineButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.e(TAG, "click1");
            }
        });
        shineButton.setOnCheckStateChangeListener(new ShineButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(View view, boolean checked) {
                Log.e(TAG, "click2 " + checked);
            }
        });

        porterShapeImageView2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.e(TAG, "click3");
            }
        });
        porterShapeImageView3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.e(TAG, "click4");
            }
        });
    }
}

4.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

    <LinearLayout
        android:id="@+id/wrapper"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="50dp"
        android:orientation="horizontal">

        <com.sackcentury.shinebuttonlib.ShineButton
            android:id="@+id/po_image0"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_centerInParent="true"
            android:layout_marginLeft="60dp"
            app:btn_color="@android:color/darker_gray"
            app:btn_fill_color="#999933"
            app:siShape="@raw/heart" />

        <com.sackcentury.shinebuttonlib.ShineButton
            android:id="@+id/po_image1"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_centerInParent="true"
            android:layout_marginLeft="20dp"
            android:src="@android:color/darker_gray"
            app:allow_random_color="false"
            app:big_shine_color="#FF6666"
            app:btn_color="@android:color/darker_gray"
            app:btn_fill_color="#FF6666"
            app:click_animation_duration="200"
            app:enable_flashing="false"
            app:shine_animation_duration="1500"
            app:shine_count="15"
            app:shine_distance_multiple="1.5"
            app:shine_turn_angle="10"
            app:siShape="@raw/like"
            app:small_shine_color="#CC9999"
            app:small_shine_offset_angle="20" />

        <com.sackcentury.shinebuttonlib.ShineButton
            android:id="@+id/po_image2"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_centerInParent="true"
            android:layout_marginLeft="20dp"
            android:src="@android:color/darker_gray"
            app:allow_random_color="true"
            app:btn_color="@android:color/darker_gray"
            app:btn_fill_color="#F44336"
            app:siShape="@raw/smile" />

        <com.sackcentury.shinebuttonlib.ShineButton
            android:id="@+id/po_image3"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_centerInParent="true"
            android:layout_marginLeft="20dp"
            app:btn_color="@android:color/darker_gray"
            app:btn_fill_color="#996699"
            app:enable_flashing="true"
            app:shine_size="40dp"
            app:siShape="@raw/star" />
    </LinearLayout>

</RelativeLayout>

5.ShineButton常用的方法说明
这里写图片描述

  • 3
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值