Я хочу, чтобы значения в средстве выбора чисел были белыми. Я сделал следующий код, который сделал его черным по умолчанию.
XML-код:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@layout/gradient_blue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="25sp"
android:textColor="#fff"
android:textStyle="bold"
android:text="Please select difficulty level"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@drawable/category_seperator"/>
<LinearLayout
android:padding="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<NumberPicker
android:id="@+id/numberPicker1"
android:layout_width="wrap_content"
android:minWidth="100dp"
android:layout_margin="10dp"
android:layout_height="wrap_content"/>
<!--#019687-->
<Button
android:background="#019687"
android:id="@+id/setting_confirm"
android:layout_width="wrap_content"
android:layout_margin="10dp"
android:layout_height="wrap_content"
android:textSize="30sp"
android:textColor="#fff"
android:padding="15dp"
android:text="OK"/>
</LinearLayout>
</LinearLayout>
Java-код:
final Dialog d = new Dialog(context);
d.requestWindowFeature(Window.FEATURE_NO_TITLE);
d.setContentView(R.layout.dialog_settings);
final NumberPicker n = (NumberPicker) d.findViewById(R.id.numberPicker1);
String easy = Html.fromHtml("<font color=\"white\">EASY</font>").toString();
String medium = Html.fromHtml("<font color=\"white\">MEDIUM</font>")+"";
String hard = Html.fromHtml("<font color=\"white\">HARD</font>")+"";
String tough = Html.fromHtml("<font color=\"white\">TOUGH</font>")+"";
// String[] a = {"EASY", "MEDIUM", "HARD", "TOUGH"};
String [ ] a = {easy,medium,hard,tough};
n.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
n.setDisplayedValues(a);
n.setMaxValue(3);
n.setMinValue(0);
n.setWrapSelectorWheel(true);
d.show();
Я попытался изменить цвет с помощью html, как показано в коде. Я также попытался изменить цвет с помощью getChildAt и преобразовать его в TextView, что привело к сбою приложения.
Color
. Например,Color.RED
- person Eric B.   schedule 11.11.2015