解决spinner文字白色看不清问题

This commit is contained in:
sonichy 2024-01-21 13:00:53 +08:00
parent 6c46f679ff
commit dca98e5a5c
4 changed files with 47 additions and 26 deletions

BIN
app.apk

Binary file not shown.

View File

@ -56,6 +56,8 @@ public class FavoriteActivity extends Activity {
ListView listView;
SimpleCursorAdapter adapter;
Spinner spinner;
ArrayList<String> list = new ArrayList<>();
ArrayAdapter adapter_category;
int position = 0;
@Override
@ -78,7 +80,8 @@ public class FavoriteActivity extends Activity {
spinner = (Spinner) findViewById(R.id.spinner);
spinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Log.e(Thread.currentThread().getStackTrace()[2] + "", "spinner: " + arg2);
TextView textView = (TextView) arg1;
textView.setTextColor(Color.BLACK);
IMM.hideSoftInputFromWindow(editText.getWindowToken(), 0);
String s = arg0.getItemAtPosition(arg2).toString();
search(1, s);
@ -294,21 +297,29 @@ public class FavoriteActivity extends Activity {
editText_title.setHint("网址");
editText_url.setText(url);
layout.addView(editText_url);
final Spinner spinner = new Spinner(this);
spinner.setBackgroundColor(Color.GRAY);
ArrayList<String> list = new ArrayList<>();
DBHelper helper = new DBHelper(this);
Cursor cursor = helper.category();
if (cursor != null) {
while (cursor.moveToNext()) {
String s = cursor.getString(cursor.getColumnIndex("category"));
list.add(s);
final Spinner spinner1 = new Spinner(this);
// ArrayList<String> list = new ArrayList<>();
// DBHelper helper = new DBHelper(this);
// Cursor cursor = helper.category();
// if (cursor != null) {
// while (cursor.moveToNext()) {
// String s = cursor.getString(cursor.getColumnIndex("category"));
// list.add(s);
// }
// }
// ArrayAdapter adapter = new ArrayAdapter(getApplicationContext(), android.R.layout.simple_spinner_item, list);
spinner1.setAdapter(adapter_category);
spinner1.setSelection(list.indexOf(category));
spinner1.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
TextView textView = (TextView) arg1;
textView.setTextColor(Color.BLACK);
IMM.hideSoftInputFromWindow(editText_title.getWindowToken(), 0);
}
}
ArrayAdapter adapter = new ArrayAdapter(getApplicationContext(), android.R.layout.simple_spinner_item, list);
spinner.setAdapter(adapter);
spinner.setSelection(list.indexOf(category));
layout.addView(spinner);
public void onNothingSelected(AdapterView<?> arg0) {
}
});
layout.addView(spinner1);
AlertDialog.Builder builder = new AlertDialog.Builder(FavoriteActivity.this);
builder.setIcon(android.R.drawable.btn_star_big_on);
builder.setTitle("修改收藏");
@ -331,7 +342,7 @@ public class FavoriteActivity extends Activity {
ContentValues values = new ContentValues();
values.put("website", surl);
values.put("title", stitle);
values.put("category", spinner.getSelectedItem().toString());
values.put("category", spinner1.getSelectedItem().toString());
int i = db.update(DBHelper.TableName, values, "_id = " + sid, null);
if (i != -1) {
IMM.hideSoftInputFromWindow(editText_title.getWindowToken(), 0);
@ -386,11 +397,15 @@ public class FavoriteActivity extends Activity {
case 4:
position = listView.getFirstVisiblePosition();
int id = Integer.parseInt(((TextView) menuInfo.targetView.findViewById(R.id.id)).getText().toString());
helper = new DBHelper(getApplicationContext());
DBHelper helper = new DBHelper(getApplicationContext());
int i = helper.del(id);
if (i != -1)
search(0, editText.getText().toString());
else
if (i != -1) {
String s = spinner.getSelectedItem().toString();
if (s.equals(""))
search(0, editText.getText().toString());
else
search(1, s);
} else
Toast.makeText(getApplicationContext(), "删除失败", Toast.LENGTH_SHORT).show();
break;
}
@ -436,7 +451,7 @@ public class FavoriteActivity extends Activity {
void genCategory() {
IMM.hideSoftInputFromWindow(editText.getWindowToken(), 0);
ArrayList<String> list = new ArrayList<>();
list.clear();
DBHelper helper = new DBHelper(this);
Cursor cursor = helper.category();
if (cursor != null) {
@ -444,8 +459,8 @@ public class FavoriteActivity extends Activity {
String s = cursor.getString(cursor.getColumnIndex("category"));
list.add(s);
}
ArrayAdapter adapter = new ArrayAdapter(getApplicationContext(), android.R.layout.simple_spinner_item, list);
spinner.setAdapter(adapter);
adapter_category = new ArrayAdapter(getApplicationContext(), android.R.layout.simple_spinner_item, list);
spinner.setAdapter(adapter_category);
}
}

View File

@ -325,7 +325,6 @@ public class FavoriteActivity1 extends Activity {
editText_url.setText(url);
layout.addView(editText_url);
final Spinner spinner = new Spinner(this);
spinner.setBackgroundColor(Color.GRAY);
ArrayList<String> list = new ArrayList<>();
DBHelper helper = new DBHelper(this);
Cursor cursor = helper.category();
@ -338,6 +337,14 @@ public class FavoriteActivity1 extends Activity {
ArrayAdapter adapter = new ArrayAdapter(getApplicationContext(), android.R.layout.simple_spinner_item, list);
spinner.setAdapter(adapter);
spinner.setSelection(list.indexOf(category));
spinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
TextView textView = (TextView) arg1;
textView.setTextColor(Color.BLACK);
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
layout.addView(spinner);
AlertDialog.Builder builder = new AlertDialog.Builder(FavoriteActivity1.this);
builder.setIcon(android.R.drawable.btn_star_big_on);

View File

@ -14,8 +14,7 @@
<Spinner
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#888" />
android:layout_height="match_parent" />
<EditText
android:id="@+id/editText"