add prefixColor attribute to PrefixedEditText

This commit is contained in:
Vincent Breitmoser
2018-04-16 14:49:01 +02:00
parent 9bb19a3ad7
commit 45c481c067
2 changed files with 7 additions and 4 deletions

View File

@@ -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();

View File

@@ -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>