我在爲Spinner設置文本顏色時遇到問題。我看過幾個例子,但是大多數的數組都是從strings.xml
開始的res folder
的ArrayAdapter和String數組,因爲我的Spinner的項目是從SQLite數據庫中檢索的,所以我認爲它可能沒有幫助。
如何在Spinner中設置項目的文本顏色Android
這裏是我的微調的代碼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
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" />
請如何設置項目中的文字顏色幫我微調。
我會感謝您提供的任何幫助。謝謝。! =)
請檢查這個鏈接。 http://stackoverflow.com/a/6661762/614807 –