0

I have TWO questions..


( 1 ) - I would like my EditText's HINT size to be smaller than the user's entered TEXT size.. Since this doesn't seem to be possible using the default layout controls, I pursue'd the answer here on Stack.

After researching, I found this - however you cannot use "sp" for the size value:

Create a string <string name="edittext_hint"><font size="15">Hint here!</font></string>
and then set android:hint="@string/edittext_hint" in your layout xml..

But, again, since you can't use "sp" for the value, I continued searching, and found this code:

// Set HINT size via XML EDITOR - and use THIS CODE to set ACTUAL TEXT size:

int actualTextSize = 16;

EditText editText = (EditText) findViewById(R.id.editTextId);
editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, actualTextSize);

//  THEN SET HINT SIZE IN LAYOUT XML EDITOR

But is it truly that simple ? And if so, why are there so many other answers doing it using an excessive amount of code to achieve what is for all intents and purposes the exact same result?
.. Is the above method correct, and is it the simplest best practice solution?


aaaand

( 2 ) - I would also like my EditText's HINT to be semi-Transparent, but NOT the 'ACTUAL TEXT'..
..IS THIS POSSIBLE? and if so, HOW?


Thanks in advance for any help provided for either of these questions!

Studio2bDesigns
  • 578
  • 5
  • 12
  • I tried using the "simple" code snippet I posted above, and I got a crash - I assume it's because the size set for the edittext text in the resource file contradicted the one I set in code (I realized that you cannot set the Hint Size in the layout file).. Does anybody else know HOW I can go about having different Text-Sizes for the HINT text, and the User-Entered text? – Studio2bDesigns Jan 30 '19 at 11:47

1 Answers1

0

Your 2nd question answer : add below property in your EditText android:textColorHint="#DD000000"

<EditText
        android:layout_width="match_parent"
        android:layout_height="70dp"
        android:hint="@string/app_name"
        android:textColorHint="#DD000000"/>

For EditText's hint text color transparent use value: for 50% white you'd use #80FFFFFF.

  • 100% — FF
  • 95% — F2
  • 90% — E6
  • 85% — D9
  • 80% — CC
  • 75% — BF
  • 70% — B3
  • 65% — A6
  • 60% — 99
  • 55% — 8C
  • 50% — 80
  • 45% — 73
  • 40% — 66
  • 35% — 59
  • 30% — 4D
  • 25% — 40
  • 20% — 33
  • 15% — 26
  • 10% — 1A
  • 5% — 0D
  • 0% — 00

(Source)

Happy Coding :)

  • Thank you for the info about transparency. I was thinking about that after I posted it, and figured that was the case.. But wouldnt it work the exact same if I were to just put the Alpha amount prior to the 6-digit HEX? For example: #50FFFFFF for a 50% Transparent 50% Opaque White? Why would 50% be #80FFFFFF? Wouldnt that be 80%/20%? Or am I completely wrong? Thanks. – Studio2bDesigns Jan 30 '19 at 11:46