Android Button收藏_点赞_评论等按钮点击效果源代码
2016-01-20 14:05:58  By: dwtedx

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

android按钮点击动画特效


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

若资源对你有帮助、浏览后有很大收获、不妨小额打赏我一下、你的鼓励是维持我不断写博客最大动力

想获取DD博客最新代码、你可以扫描下方的二维码、关注DD博客微信公众号(ddblogs)

或者你也可以关注我的新浪微博、了解DD博客的最新动态:DD博客官方微博(dwtedx的微博)

如对资源有任何疑问或觉得仍然有很大的改善空间、可以对该博文进行评论、希望不吝赐教

为保证及时回复、可以使用博客留言板给我留言: DD博客留言板(dwtedx的留言板)

感谢你的访问、祝你生活愉快、工作顺心、欢迎常来逛逛


快速评论


技术评论

  • 该技术还没有评论、赶快抢沙发吧...
DD记账
top
+