Android:hint使用的颜色代码是什么?我的意思是灰色。
Android:hint使用的颜色代码是什么?我的意思是灰色。
R: 128
G: 128
B: 128
或者
< p >#808080
在您的XML中使用以下内容:
android:textColor="?android:textColorHint"
尝试使用 #a8a8a8 :)
在 res/value 文件夹中创建一个名为 color.xml 的文件
然后像这样定义它:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="gray">#a8a8a8</color>
</resources>
然后像这样使用它:
android.graphics.Color.gray;
要获取提示文字颜色,您可以使用getCurrentHintTextColor()。然后需要将int值转换为十六进制格式。例如:
EditText et = (EditText) findViewById(R.id.edit_text);
int c = et.getCurrentHintTextColor();
Log.d("Hint color", String.format("%X", c));
<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%
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会显示其他可能的选项。
希望这能帮到你。
在代码中:
它是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"
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"/>