我遇到了设置Spinner文本颜色的问题。我看过一些例子,但是大多数都使用ArrayAdapter和res文件夹
中的String数组从strings.xml
获取Spinner的项,因为我的Spinner项是从SQLite数据库中检索的,所以我认为这可能没有帮助。
下面是PersonalInformation.java中的Spinner代码:
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中的项目文本颜色。非常感谢您提供的任何帮助。谢谢!=)