-
Notifications
You must be signed in to change notification settings - Fork 212
Open
Description
you need download code and change two file
1.change MaterialSpinner.java
first change init:
private int selectedIndex = -1;
////second change setAdapterInternal :
private void setAdapterInternal(@NonNull MaterialSpinnerBaseAdapter adapter) {
boolean shouldResetPopupHeight = listView.getAdapter() != null;
adapter.setHintEnabled(!TextUtils.isEmpty(hintText));
listView.setAdapter(adapter);
if (selectedIndex >= adapter.getCount()) {
selectedIndex = 0;
}
if (adapter.getItems().size() > 0 && selectedIndex >= 0) {
if (nothingSelected && !TextUtils.isEmpty(hintText)) {
setText(hintText);
setHintColor(hintColor);
} else {
setTextColor(textColor);
setText(adapter.get(selectedIndex).toString());
}
} else {
String text = "please select";
if(!TextUtils.isEmpty(hintText)){
text = hintText;
}
setText(text);
}
if (shouldResetPopupHeight) {
popupWindow.setHeight(calculatePopupWindowHeight());
}
}
- in xml file, set hint text
<xxxxxx.MaterialSpinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="44dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:elevation="1dp"
app:ms_hint="custom hint text"
android:textColor="#D9000000" />
now success!
Metadata
Metadata
Assignees
Labels
No labels