allprojects {
repositories {
...
maven { url "https://jitpack.io" }
}
}
dependencies {
compile 'com.github.Brioal:ADTextView:1.2'
}
<com.brioal.adtextviewlib.view.ADTextView
android:id="@+id/ad_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@color/colorPrimary"
android:gravity="center"
android:padding="10dp"
/>
mADTextView = findViewById(R.id.ad_textview);
final List<String> texts = new ArrayList<>();
texts.add("11 111111111111111");
texts.add("22 2222222222222222");
texts.add("33 3333333333333333");
texts.add("44 44444444444444444444");
mADTextView.setInterval(2000);
mADTextView.init(texts,new OnAdChangeListener() {
@Override
public void DiyTextView(TextView textView, final int index) {
textView.setTextSize(20);
textView.setTextColor(Color.WHITE);
SpannableStringBuilder builder = new SpannableStringBuilder(textView.getText());
builder.setSpan(new ForegroundColorSpan(Color.RED), 0, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(builder);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(AdTextViewActivity.this, "点击了第" + (index + 1) + "个TextView", Toast.LENGTH_SHORT).show();
}
});
}
});