-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b97359
commit 7eda6f9
Showing
2 changed files
with
80 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package view; | ||
|
||
import android.content.Context; | ||
import android.graphics.Canvas; | ||
import android.graphics.Color; | ||
import android.graphics.Paint; | ||
import android.graphics.Rect; | ||
import android.text.Layout; | ||
import android.util.AttributeSet; | ||
|
||
import androidx.annotation.Nullable; | ||
|
||
import com.zone.lib.utils.view.DrawUtils; | ||
|
||
public class BGTextView extends androidx.appcompat.widget.AppCompatEditText { | ||
public BGTextView(Context context) { | ||
super(context); | ||
} | ||
|
||
public BGTextView(Context context, @Nullable AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
public BGTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { | ||
super(context, attrs, defStyleAttr); | ||
} | ||
|
||
Paint paint2 = DrawUtils.getStrokePaint(Paint.Style.STROKE, 3); | ||
int[] colorArry = new int[]{Color.CYAN, Color.GREEN, Color.YELLOW}; | ||
Rect rect = new Rect(); | ||
|
||
@Override | ||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | ||
super.onMeasure(widthMeasureSpec, heightMeasureSpec); | ||
setMeasuredDimension(getMeasuredWidth(), (int) (getMeasuredHeight() + getLineSpacingExtra())); | ||
} | ||
|
||
@Override | ||
protected void onDraw(Canvas canvas) { | ||
super.onDraw(canvas); | ||
float lineSpacingExtra = getLineSpacingExtra(); | ||
try { | ||
Layout layout = getLayout(); | ||
int lineCount = layout.getLineCount(); | ||
for (int i = 0; i < lineCount; i++) { | ||
paint2.setColor(colorArry[i % colorArry.length]); | ||
layout.getLineBounds(i, rect); | ||
if (i == lineCount - 1) { | ||
rect.bottom += lineSpacingExtra; | ||
} | ||
canvas.drawRect(rect, paint2); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |