简体   繁体   中英

Q: Android - (EditText) Hint vs Text Sizes + Alpha only on Hint Text?

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!

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM