add prefixColor attribute to PrefixedEditText
This commit is contained in:
@@ -30,7 +30,8 @@ import org.sufficientlysecure.keychain.R;
|
|||||||
|
|
||||||
public class PrefixedEditText extends AppCompatEditText {
|
public class PrefixedEditText extends AppCompatEditText {
|
||||||
|
|
||||||
private String mPrefix;
|
private CharSequence mPrefix;
|
||||||
|
private int mPrefixColor;
|
||||||
private int desiredWidth;
|
private int desiredWidth;
|
||||||
|
|
||||||
public PrefixedEditText(Context context, AttributeSet attrs) {
|
public PrefixedEditText(Context context, AttributeSet attrs) {
|
||||||
@@ -38,6 +39,7 @@ public class PrefixedEditText extends AppCompatEditText {
|
|||||||
TypedArray style = context.getTheme().obtainStyledAttributes(
|
TypedArray style = context.getTheme().obtainStyledAttributes(
|
||||||
attrs, R.styleable.PrefixedEditText, 0, 0);
|
attrs, R.styleable.PrefixedEditText, 0, 0);
|
||||||
mPrefix = style.getString(R.styleable.PrefixedEditText_prefix);
|
mPrefix = style.getString(R.styleable.PrefixedEditText_prefix);
|
||||||
|
mPrefixColor = style.getColor(R.styleable.PrefixedEditText_prefixColor, getCurrentTextColor());
|
||||||
if (mPrefix == null) {
|
if (mPrefix == null) {
|
||||||
mPrefix = "";
|
mPrefix = "";
|
||||||
}
|
}
|
||||||
@@ -54,8 +56,8 @@ public class PrefixedEditText extends AppCompatEditText {
|
|||||||
super.onDraw(canvas);
|
super.onDraw(canvas);
|
||||||
TextPaint paint = getPaint();
|
TextPaint paint = getPaint();
|
||||||
// reset to the actual text color - it might be the hint color currently
|
// reset to the actual text color - it might be the hint color currently
|
||||||
paint.setColor(getCurrentTextColor());
|
paint.setColor(mPrefixColor);
|
||||||
canvas.drawText(mPrefix, super.getCompoundPaddingLeft(), getBaseline(), paint);
|
canvas.drawText(mPrefix, 0, mPrefix.length(), super.getCompoundPaddingLeft(), getBaseline(), paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -63,7 +65,7 @@ public class PrefixedEditText extends AppCompatEditText {
|
|||||||
return super.getCompoundPaddingLeft() + desiredWidth;
|
return super.getCompoundPaddingLeft() + desiredWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPrefix(String prefix) {
|
public void setPrefix(CharSequence prefix) {
|
||||||
mPrefix = prefix;
|
mPrefix = prefix;
|
||||||
|
|
||||||
invalidate();
|
invalidate();
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
<declare-styleable name="PrefixedEditText">
|
<declare-styleable name="PrefixedEditText">
|
||||||
<attr name="prefix" format="string" />
|
<attr name="prefix" format="string" />
|
||||||
|
<attr name="prefixColor" format="color" />
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user