In my application, I create custom TextView
and I change colors in Java file.
But I want to change this colors with XML file such as some Android libraries.
My Java code for custom TextView:
public class GradientTextView extends AppCompatTextView {
public GradientTextView(Context context) {
super(context);
}
public GradientTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public GradientTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
//Setting the gradient if the layout is changed
if (changed) {
getPaint().setShader(new LinearGradient(0, 0, getWidth(), getHeight(),
ContextCompat.getColor(getContext(), R.color.gradientTextColor2),
ContextCompat.getColor(getContext(), R.color.tabCategoryColor),
Shader.TileMode.MIRROR));
}
}
}
I want change this parameter in XML code :
ContextCompat.getColor(getContext(), R.color.gradientTextColor2),
ContextCompat.getColor(getContext(), R.color.tabCategoryColor),
My XML code:
<com.mcc.wpnews.view.GradientTextView
android:id="@+id/navHeader_notVipBuyTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="@string/buyVip"
android:textSize="@dimen/font16" />
How can do achieve this, or is it something that I am missing? Please help me