简体   繁体   English

问:Android-(EditText)提示与文本大小+仅在提示文本上使用Alpha吗?

[英]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. (1)-我希望EditText的HINT尺寸小于用户输入的TEXT尺寸。由于使用默认的布局控件似乎无法做到这一点,因此我在此处寻求答案。

After researching, I found this - however you cannot use "sp" for the size value: 经过研究,我发现了这一点-但是您不能使用“ sp”作为大小值:

Create a string <string name="edittext_hint"><font size="15">Hint here!</font></string> 在这里创建一个字符串<string name="edittext_hint"><font size="15">Hint here!</font></string>
and then set android:hint="@string/edittext_hint" in your layout xml.. 然后在布局xml中设置android:hint="@string/edittext_hint"

But, again, since you can't use "sp" for the value, I continued searching, and found this code: 但是,再次,由于您不能使用“ sp”作为值,因此我继续搜索并找到以下代码:

// Set HINT size via XML EDITOR - and use THIS CODE to set ACTUAL TEXT size: //通过XML EDITOR设置提示大小-并使用此代码设置ACTUAL TEXT大小:

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 aaaand

( 2 ) - I would also like my EditText's HINT to be semi-Transparent , but NOT the 'ACTUAL TEXT'.. (2)-我也希望我的EditText的提示是半透明的 ,而不是 “ 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中添加以下属性: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. 对于EditText的提示文本颜色透明使用值:对于50%的白色,您将使用#80FFFFFF。

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

( Source ) 来源

Happy Coding :) 快乐编码:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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