Skip to content

liuchch/SmartTextView

Repository files navigation

SmartTextView

一个聪明的TextView 1.0.1版本已经可以实现对于一段文字中的部分文字更改字体颜色,以及添加点击事件。

一.需要将strings.xml文件中的文字通过"(-"和"-)"包起来。

例如 (-S-)mart(-T-)ext(-V-)(-iew-)

二.通过SmartText添加SmartTextStyle对"(- -)"里面中的内容设置颜色 以及增加点击事件。

点击事件和文字下划线都是可选功能,如下所示

SmartText smartText = new SmartText(tv1, getResources().getString(R.string.SmartTextView));
        smartText
                .addTextStyle(new SmartTextStyle()
                                .setTextColor(getResources().getColor(R.color.colorPrimary))
                )
                .addTextStyle(new SmartTextStyle()
                        .setTextColor(getResources().getColor(R.color.colorPrimaryDark))
                        .setListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                Toast.makeText(MainActivity.this, "我可以点!!!", Toast.LENGTH_LONG).show();
                            }
                        })
                        .setWithUnderLine(true)
                )
                .addTextStyle(
                        new SmartTextStyle().setTextColor(getResources().getColor(R.color.dark))
                        .setListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                Toast.makeText(MainActivity.this, "我不能点啊为什么点我,哼!!!", Toast.LENGTH_LONG).show();
                            }
                        })
                )
//                .addTextStyle(new SmartTextStyle().setTextColor(getResources().getColor(R.color.colorPrimaryDark)))
                .finish();

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages