使用Android SpannableString设置TextView局部文字颜色

样式文件:

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="欢迎来到枫林的小窝!"/>

代码文件:

private void initTextView() {
    TextView textView = findViewById(R.id.textView);
    SpannableString spannableString = new SpannableString(textView.getText());
    setTextColor(spannableString, "枫林的小窝", Color.BLUE);
    textView.setText(spannableString);
}

/**
 * 设置SpannableString指定文字的颜色
 *
 * @param spannableString
 * @param text
 * @param color
 */
private void setTextColor(SpannableString spannableString, String text, int color) {
    int start = spannableString.toString().indexOf(text);
    int end = start + text.length();
    spannableString.setSpan(new ForegroundColorSpan(color), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}

参考链接:

Android开发 SpannableString开发详解

Android UI——SpannableString详细解析

Android使用VLC播放摄像头RTSP流

1.修改项目build.gradle,增加maven库地址

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://dl.bintray.com/videolan/Android" }
    }
}

2.修改模块build.gradle,增加依赖

// VLC 最新版本
implementation 'org.videolan.android:libvlc-all:3.2.1'

3.布局文件中加入VLCVideoLayout

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
    tools:context=".MainActivity">

    <org.videolan.libvlc.util.VLCVideoLayout
        android:id="@+id/video_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

继续阅读Android使用VLC播放摄像头RTSP流