VectorCompatTextView 开源项目教程

VectorCompatTextView 开源项目教程

VectorCompatTextViewOne VectorCompatTextView suits for hundreds of CompoundDrawable style. 一个库,满足CompoundDrawable的百变风格。项目地址:https://gitcode.com/gh_mirrors/ve/VectorCompatTextView

项目介绍

VectorCompatTextView 是一个开源项目,旨在提供一个灵活的 TextView 组件,支持多种复合图标(CompoundDrawable)风格。该项目由 woxingxiao 开发,并在 GitHub 上托管。通过使用 VectorCompatTextView,开发者可以轻松地在文本视图中添加和自定义图标,而无需编写复杂的代码。

项目快速启动

添加依赖

首先,在您的项目的 build.gradle 文件中添加以下依赖:

implementation 'com.github.woxingxiao:VectorCompatTextView:$[LATEST_VERSION]-androidx'

请确保将 $[LATEST_VERSION] 替换为最新的版本号。

使用示例

在您的布局文件中添加 VectorCompatTextView:

<com.xw.repo.VectorCompatTextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="GitHub"
    app:drawableLeftCompat="@drawable/svg_ic_github"/>

在您的 Activity 或 Fragment 中初始化并使用 VectorCompatTextView:

import com.xw.repo.VectorCompatTextView;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final VectorCompatTextView checkableTv1 = findViewById(R.id.checkable_text_view1);
        checkableTv1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                checkableTv1.toggle();
                checkableTv1.setText(checkableTv1.isChecked() ? "SELECTED TAB" : "UNSELECTED TAB");
            }
        });
    }
}

应用案例和最佳实践

案例一:切换日夜间模式

final VectorCompatTextView checkableTv2 = findViewById(R.id.checkable_text_view2);
checkableTv2.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        checkableTv2.toggle();
        checkableTv2.setText(checkableTv2.isChecked() ? "Night Mode" : "Day Mode");
    }
});

案例二:自定义图标颜色

<com.xw.repo.VectorCompatTextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="ON"
    app:drawableCompatColor="#f44336"
    app:drawableBottomCompat="@drawable/svg_ic_line"/>

典型生态项目

VectorCompatTextView 可以与其他开源项目结合使用,例如:

  • Material Design Components: 结合 Material Design 组件,提供更加丰富的用户界面。
  • Glide: 使用 Glide 加载网络图片,并将其作为图标显示在 VectorCompatTextView 中。
  • Retrofit: 结合 Retrofit 进行网络请求,动态更新 VectorCompatTextView 中的内容。

通过这些组合,可以构建出功能强大且美观的应用程序。

VectorCompatTextViewOne VectorCompatTextView suits for hundreds of CompoundDrawable style. 一个库,满足CompoundDrawable的百变风格。项目地址:https://gitcode.com/gh_mirrors/ve/VectorCompatTextView

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

张姿桃Erwin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值