Skip to content

Commit 0e54710

Browse files
author
mobyiapps
committed
Update
1 parent ffb3397 commit 0e54710

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

app/src/main/res/layout/activity_main.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@
115115
android:text="Custom Button"
116116
app:button_font="Smoothy.otf" />
117117

118+
<com.dvinfosys.widgets.TextView.GradientTextView
119+
android:layout_width="match_parent"
120+
android:layout_height="wrap_content"
121+
android:text="Gradient TextView"
122+
android:textSize="18dp"
123+
android:gravity="center"
124+
app:gradientEnd="#6673E7"
125+
app:gradientStart="#FF0000" />
126+
118127
<com.dvinfosys.widgets.VideoPlayer.VPVideoPlayerStandard
119128
android:id="@+id/vp_videoplayer"
120129
android:layout_width="match_parent"
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.dvinfosys.widgets.TextView;
2+
3+
import android.annotation.TargetApi;
4+
import android.content.Context;
5+
import android.content.res.TypedArray;
6+
import android.graphics.LinearGradient;
7+
import android.graphics.Shader;
8+
import android.graphics.Typeface;
9+
import android.os.Build;
10+
import android.util.AttributeSet;
11+
import android.widget.TextView;
12+
13+
import com.dvinfosys.widgets.R;
14+
import com.dvinfosys.widgets.Utils.TextFontCache;
15+
16+
/**
17+
* Created by DV Bhuva on 27/06/19.
18+
*/
19+
20+
public class GradientTextView extends TextView {
21+
22+
int startColor, endColor;
23+
Shader shader;
24+
25+
public GradientTextView(Context context) {
26+
super(context);
27+
}
28+
29+
public GradientTextView(Context context, AttributeSet attrs) {
30+
super(context, attrs);
31+
if (!isInEditMode())
32+
createShader(context, attrs, 0);
33+
}
34+
35+
public GradientTextView(Context context, AttributeSet attrs, int defStyleAttr) {
36+
super(context, attrs, defStyleAttr);
37+
if (!isInEditMode())
38+
createShader(context, attrs, defStyleAttr);
39+
}
40+
41+
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
42+
public GradientTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
43+
super(context, attrs, defStyleAttr, defStyleRes);
44+
if (!isInEditMode())
45+
createShader(context, attrs, defStyleAttr);
46+
}
47+
48+
49+
public void createShader(Context context, AttributeSet attrs, int defStyleAttr) {
50+
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GradientTextView, defStyleAttr, 0);
51+
try {
52+
startColor = a.getInt(R.styleable.GradientTextView_gradientStart, 0);
53+
endColor = a.getInt(R.styleable.GradientTextView_gradientEnd, 0);
54+
shader = new LinearGradient(0, 0, 0, getTextSize(),
55+
new int[]{startColor, endColor},
56+
new float[]{0, 1}, Shader.TileMode.CLAMP);
57+
getPaint().setShader(shader);
58+
} finally {
59+
a.recycle();
60+
}
61+
Typeface customFont = TextFontCache.getTypeface("Poppins.ttf", context);
62+
setTypeface(customFont);
63+
}
64+
}

libraries/src/main/res/values/attrs.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,9 @@
9898
<declare-styleable name="CustomToggleButton">
9999
<attr name="togglebutton_font" format="string"/>
100100
</declare-styleable>
101+
102+
<declare-styleable name="GradientTextView">
103+
<attr name="gradientStart"/>
104+
<attr name="gradientEnd"/>
105+
</declare-styleable>
101106
</resources>

libraries/src/main/res/values/colors.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66
<color name="successColor">#388E3C</color>
77
<color name="warningColor">#FFA900</color>
88
<color name="normalColor">#353A3E</color>
9+
<color name="colorStart">#520000</color>
10+
<color name="colorEnd">#F7C0C0</color>
911
</resources>

0 commit comments

Comments
 (0)