【问题标题】:What's the Color code for Android Hint?Android 提示的颜色代码是什么?
【发布时间】:2014-04-15 03:12:01
【问题描述】:

Android:hint 使用的颜色代码是什么? 我的意思是灰色。

【问题讨论】:

  • 你在谈论什么?你有什么问题?
  • 我认为他想知道确切的颜色为 rgb 十六进制字符串。
  • @Kai 是的,提示“由”组成的确切十六进制代码。
  • 库存 android 使用的确切颜色十六进制

标签: java android colors hex


【解决方案1】:
R: 128 
G: 128 
B: 128

#808080

【讨论】:

  • @lapadets 提供的颜色更符合我的 nexus 7,Android 5.1 上的提示
  • #9E9E9E 在我的设备中似乎更匹配。 #808080 太暗,而 #A8A8A8 比默认提示颜色浅一点。如果颜色应该准确匹配,最好的选择是使用@Pomanh 的解决方案。
【解决方案2】:

在你的 xml 中使用这个:

    android:textColor="?android:textColorHint"

【讨论】:

  • #808080 太暗了,这个完美
【解决方案3】:

试试#a8a8a8 :)

在 res/value 文件夹中创建 color.xml 文件

然后这样定义:

<?xml version="1.0" encoding="utf-8"?>
<resources>
 <color name="gray">#a8a8a8</color>
</resources>

然后像这样使用它:

android.graphics.Color.gray;

【讨论】:

  • 别叫它灰色。给它一个代表颜色应用的名称。称之为“hintColor”之类的。
【解决方案4】:

要获得提示颜色,您可以使用 getCurrentHintTextColor()。 然后您需要将 int 转换为 hex 格式。 例如:

EditText et = (EditText) findViewById(R.id.edit_text);
        int c = et.getCurrentHintTextColor();
        Log.d("Hint color", String.format("%X", c));

【讨论】:

    【解决方案5】:

    在来源中,全息主题:

    <color name="hint_foreground_holo_light">#808080</color>
    <color name="hint_foreground_holo_dark">#808080</color>
    

    材质主题:

    <color name="foreground_material_dark">@android:color/white</color>
    <item format="float" name="hint_alpha_material_dark" type="dimen">0.50</item>
    
    <color name="foreground_material_light">@android:color/black</color>      
    <item format="float" name="hint_alpha_material_light" type="dimen">0.38</item>
    

    所以对于浅色主题,您可以使用#61000000 //black 38%

    对于深色主题#80ffffff //white 50%

    【讨论】:

      【解决方案6】:

      最好的方法是使用 R、G、B 通道输入颜色值。 对于灰色,

          R=127 (hex = 7F), 
          G=127 (hex = 7F), 
          B=127 (hex = 7F),
          Hence, color-value = #7F7F7F -> go ahead and use this for gray color
      

      或者,如果您懒惰并且不想进行上述数学运算 - 您可以选择使用可用的内置颜色选项。例如,在一个简单的 TextView

      android:textColor="@android:color/black"
      

      还有更多选项,在 color/ 之后按 Ctrl + Space 将显示其他可能的选项。

      希望这会有所帮助。

      【讨论】:

        【解决方案7】:

        像这样创建一个适配器

        class SpinnerAdapter(context: Context, items: List<String>) :
            ArrayAdapter<String>(context, R.layout.spinner_item_layout, items) {
        
            override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup): View {
                val spinnerItemView = super.getDropDownView(position, null, parent) as TextView
                spinnerItemView.setBackgroundResource(R.drawable.light_gray_border_bottom_bg) // optional( here i am giving a style for spinner item)
        
                if (position == 0) {
                    spinnerItemView.setTextColor(
                        ContextCompat.getColor(
                            context,
                            R.color.hintColor
                        )
                    )
                } else {
                    spinnerItemView.setTextColor(ContextCompat.getColor(context, R.color.colorPrimaryText))
                }
                return spinnerItemView
            }
        
            override fun isEnabled(position: Int) = position != 0
        
        }
        

        这是我的spinner_item_layout 文件

        <?xml version="1.0" encoding="utf-8"?>
        <TextView
            android:padding="10dp"
            android:text="Spinner Text"
            android:textColor="?android:textColorHint"
            android:textSize="14sp"
            android:includeFontPadding="false"
            xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
        

        【讨论】:

          猜你喜欢
          • 2011-11-03
          • 2014-10-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-12-12
          • 1970-01-01
          • 2010-12-20
          • 2019-03-04
          相关资源
          最近更新 更多