Skip to content

Commit

Permalink
可以动态设置滚动字幕的颜色
Browse files Browse the repository at this point in the history
  • Loading branch information
FaceAI committed Nov 18, 2019
1 parent 1e7941a commit 89ee1f2
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 26 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
Binary file modified .idea/caches/gradle_models.ser
Binary file not shown.
15 changes: 13 additions & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@
```
scrollText = findViewById(R.id.scrollText);
scrollText.setSpeed(4);
scrollText.setText("new text"); //已经修改setText() 没能动态生效的问题
scrollText.setText("new text");
scrollText.setTextColor(0xffad43ae);
```


# Gradle 集成使用
```
implementation 'anylife.scrolltextview:ScrollTextviewLib:1.4.5'
implementation 'anylife.scrolltextview:ScrollTextviewLib:1.4.6'
```

# Maven 集成使用
```
<dependency>
<groupId>anylife.scrolltextview</groupId>
<artifactId>ScrollTextviewLib</artifactId>
<version>1.4.5</version>
<version>1.4.6</version>
<type>pom</type>
</dependency>
```
Expand Down
8 changes: 4 additions & 4 deletions ScrollTextviewLib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ apply plugin: 'com.jfrog.bintray' //jfrog


android {
compileSdkVersion 26
compileSdkVersion 28

defaultConfig {
minSdkVersion 15
targetSdkVersion 26
targetSdkVersion 28
versionCode 5
versionName "1.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -25,10 +25,10 @@ android {

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
}

version = "1.4.5" //版本号,每次提交到Jcenter都要修改
version = "1.4.6" //版本号,每次提交到Jcenter都要修改
def siteUrl = "https://github.com/AnyLifeZLB/ScrollTextView" // project homepage
def gitUrl = "https://github.com/AnyLifeZLB/ScrollTextView.git" // project git
group = "anylife.scrolltextview"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package anylife.scrolltextview;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.FontMetrics;
import android.graphics.PixelFormat;
import android.graphics.PorterDuff.Mode;
import android.support.annotation.ColorInt;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
Expand Down Expand Up @@ -48,6 +50,7 @@ public class ScrollTextView extends SurfaceView implements SurfaceHolder.Callbac
private int speed = 1; // scroll-speed
private String text = ""; // scroll text
private float textSize = 15f; // text size
private int textColor;

private int needScrollTimes = Integer.MAX_VALUE; //scroll times

Expand Down Expand Up @@ -88,7 +91,7 @@ public ScrollTextView(Context context, AttributeSet attrs) {
isHorizontal = arr.getBoolean(R.styleable.ScrollTextView_isHorizontal, isHorizontal);
speed = arr.getInteger(R.styleable.ScrollTextView_speed, speed);
text = arr.getString(R.styleable.ScrollTextView_text);
int textColor = arr.getColor(R.styleable.ScrollTextView_text_color, Color.BLACK);
textColor = arr.getColor(R.styleable.ScrollTextView_text_color, Color.BLACK);
textSize = arr.getDimension(R.styleable.ScrollTextView_text_size, textSize);
needScrollTimes = arr.getInteger(R.styleable.ScrollTextView_times, Integer.MAX_VALUE);
isScrollForever = arr.getBoolean(R.styleable.ScrollTextView_isScrollForever, true);
Expand Down Expand Up @@ -217,14 +220,24 @@ public void setHorizontal(boolean horizontal) {
*/
public void setText(String newText) {
isSetNewText = true;

stopScroll = false;
this.text = newText;

measureVarious();
}



/**
* Set the text color
*
* @param color A color value in the form 0xAARRGGBB.
*/
public void setTextColor(@ColorInt int color) {
textColor =color;
paint.setColor(textColor);
}


/**
* set scroll speed
*
Expand Down Expand Up @@ -259,10 +272,6 @@ public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
pauseScroll = !pauseScroll;
// stopScroll = !stopScroll;
// if (!stopScroll && needScrollTimes == 0) {
// needScrollTimes = Integer.MAX_VALUE;
// }
break;
}
return true;
Expand Down
8 changes: 3 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 26
compileSdkVersion 28

defaultConfig {
applicationId "com.anylife.fragment.scrolltextview"
minSdkVersion 19
targetSdkVersion 26
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
Expand All @@ -30,6 +30,4 @@ dependencies {

// implementation 'anylife.scrolltextview:ScrollTextviewLib:1.4.2' //when OK



}
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ protected void onCreate(Bundle savedInstanceState) {
scrollText.setText("你打扰到我学习了1234567890AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz");

imageView=findViewById(R.id.imageView);
imageView.setOnClickListener(this); //测试动态改变TextView




imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
scrollText.setTextColor(0xffaa3456);
}
}); //测试动态改变TextView



Expand Down

0 comments on commit 89ee1f2

Please sign in to comment.