安卓提示的颜色代码是什么?

46

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


你在说什么?你有什么问题? - M D
我认为他想知道确切的颜色,以RGB十六进制字符串的形式。 - kai
@Kai 是的,提示所“制成”的确切十六进制代码。 - Paramone
Android原生使用的确切颜色代码十六进制值是什么? - kabuto178
你是在说这个吗?http://developer.android.com/reference/android/widget/TextView.html#getHintTextColors%28%29 - donfuxx
8个回答

63
R: 128 
G: 128 
B: 128
或者 < p >#808080


1
@lapadets提供的颜色更符合我在我的Nexus 7上使用Android 5.1时的提示。 - Gem
4
在我的设备上,#9E9E9E似乎更匹配。 #808080太暗,而#A8A8A8比默认的提示颜色略亮。如果颜色需要精确匹配,则最好使用@Pomanh的解决方案。 - Abhimanyu

40

在您的XML中使用以下内容:

    android:textColor="?android:textColorHint"

#808080太暗了,这个完美。 - DIRTY DAVE

7

尝试使用 #a8a8a8 :)

在 res/value 文件夹中创建一个名为 color.xml 的文件

然后像这样定义它:

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

然后像这样使用它:

android.graphics.Color.gray;

6
不要称其为灰色,给它一个代表颜色应用的名称。可以称其为“hintColor”或其他类似的名称。 - Mark Buikema

4

要获取提示文字颜色,您可以使用getCurrentHintTextColor()。然后需要将int值转换为十六进制格式。例如:

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

3
在源代码中,Holo主题:
<color name="hint_foreground_holo_light">#808080</color>
<color name="hint_foreground_holo_dark">#808080</color>

Material 主题:

<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 //黑色 38%

而对于深色主题,则可以使用#80ffffff //白色 50%


0
最好的方法是使用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会显示其他可能的选项。

希望这能帮到你。


0

在代码中:

它是android.R.color.tab_indicator_text。您可以通过getResources().getColor(android.R.color.tab_indicator_text, null)获取它。或者您可以从RGB获取:Color.rgb(128, 128, 128)

在xml中:

添加此属性:android:textColor="?android:textColorHint"android:textColor="#FF808080"


0
请创建一个类似这样的适配器。
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"/>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接