我在为 Spinner 设置文本颜色时遇到问题。我见过几个例子,但大多数都有 ArrayAdapter 和 String 数组strings.xml
,res folder
因为我的 Spinner 的项目是从 SQLite 数据库中检索的,所以我认为它可能无济于事。
这是我的 Spinner 的代码 PersonalInformation.java
public class PersonalInformation extends Activity
{
EditText txtLikes, txtDislikes, txtType, txtDate;
Button btnView, btnBack;
Spinner nameSpinner;
final Context context = this;
private int namesSpinnerId;
LikesDBAdapter likeDB = new LikesDBAdapter(this);
DislikesDBAdapter dlikeDB = new DislikesDBAdapter(this);
@Override
public void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.info);
BuddyDBAdapter buddyDB = new BuddyDBAdapter(this);
buddyDB.open();
Cursor friendsCursor = buddyDB.getAllNames();
startManagingCursor(friendsCursor);
String[] from = new String[]{BuddyDBAdapter.KEY_NAME};
int[] to = new int[]{R.id.name};
SimpleCursorAdapter friendsCursorAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, friendsCursor, from, to);
friendsCursorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
nameSpinner = (Spinner)findViewById(R.id.nameSpinner);
nameSpinner.setAdapter(friendsCursorAdapter);
//buddyDB.close();
nameSpinner.setOnItemSelectedListener(new OnItemSelectedListener()
{
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
{
Cursor c = (Cursor)parent.getItemAtPosition(pos);
namesSpinnerId = c.getInt(c.getColumnIndexOrThrow(BuddyDBAdapter.KEY_ROWID));
}
@Override
public void onNothingSelected(AdapterView<?> parent)
{
// TODO Auto-generated method stub
}
});
buddyDB.close();
而且,这些是 info.xml 中 Spinner 的布局代码
<Spinner
style="@style/SpinnerStyle"
android:id="@+id/nameSpinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:prompt="@string/friends_prompt"
android:textColor="@color/green" />
请帮助我如何在 Spinner 中设置项目文本颜色。
我将不胜感激提供的任何帮助。谢谢。!=)