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常用的方法说明