欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  技术分享

Android Button收藏_点赞_评论等按钮点击效果源代码

程序员文章站 2022-03-01 12:36:31
...

Android按钮点击动画特效、有关注按钮点击效果、有收藏按钮、点赞按钮、评论按钮等各种效果、适合按钮效果处理、很不错的Android特效、按钮点击效果、大家可以下载看看、可以很方便的集成到自己的项目中、下面是效果图

Android Button收藏_点赞_评论等按钮点击效果源代码


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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.like.example.MainActivity"
    tools:showIn="@layout/activity_main">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:orientation="horizontal">

        <com.like.LikeButton
            app:liked="true"
            android:id="@ id/star_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:icon_size="25dp"
            app:icon_type="star" />

        <com.like.LikeButton
            android:id="@ id/heart_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:icon_size="25dp"
            app:icon_type="heart" />

        <com.like.LikeButton
            android:id="@ id/thumb_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:circle_end_color="@android:color/holo_blue_dark"
            app:circle_start_color="@android:color/holo_blue_bright"
            app:dots_primary_color="@android:color/holo_blue_light"
            app:dots_secondary_color="@android:color/holo_blue_dark"
            app:icon_size="25dp"
            app:like_drawable="@drawable/thumb_on"
            app:unlike_drawable="@drawable/thumb_off" />

        <com.like.LikeButton
            android:id="@ id/smile_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:circle_end_color="@android:color/holo_purple"
            app:circle_start_color="@android:color/holo_purple"
            app:dots_primary_color="@android:color/holo_blue_dark"
            app:dots_secondary_color="@android:color/holo_blue_light"
            app:icon_size="25dp" />
    </LinearLayout>
</RelativeLayout>


Activity代码

public class MainActivity extends AppCompatActivity implements OnLikeListener {

    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.star_button)
    LikeButton starButton;
    @Bind(R.id.heart_button)
    LikeButton likeButton;
    @Bind(R.id.thumb_button)
    LikeButton thumbButton;
    @Bind(R.id.smile_button)
    LikeButton smileButton;

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

        starButton.setOnLikeListener(this);
        likeButton.setOnLikeListener(this);
        smileButton.setOnLikeListener(this);
        thumbButton.setOnLikeListener(this);

        thumbButton.setLiked(true);

        usingCustomIcons();

    }

    public void usingCustomIcons() {

        //shown when the button is in its default state or when unLiked.
        smileButton.setUnlikeDrawable(new BitmapDrawable(getResources(), new IconicsDrawable(this, CommunityMaterial.Icon.cmd_emoticon).colorRes(android.R.color.darker_gray).sizeDp(25).toBitmap()));

        //shown when the button is liked!
        smileButton.setLikeDrawable(new BitmapDrawable(getResources(), new IconicsDrawable(this, CommunityMaterial.Icon.cmd_emoticon).colorRes(android.R.color.holo_purple).sizeDp(25).toBitmap()));

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    @Override
    public void liked(LikeButton likeButton) {
        Toast.makeText(this, "Liked!", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void unLiked(LikeButton likeButton) {
        Toast.makeText(this, "Disliked!", Toast.LENGTH_SHORT).show();
    }
}


源代码下载链接: http://dwtedx.com/download.html?bdkey=s/1sk7idop 密码: q9hx