2015-02-23 110 views
0

經過大量的搜索和沒有答案(或簡單的答案), 我有一個活動,它有一個動作欄微調(由Android演播室簡單的嚮導創建)。有一個代碼片段:如何更改下拉導航文字字體和顏色?

actionBar.setListNavigationCallbacks(

      new ArrayAdapter<String>(
        actionBar.getThemedContext(), 
        android.R.layout.simple_list_item_1, 
        android.R.id.text1, 
        new String[]{ 
          getString(R.string.title_section1), 
          getString(R.string.title_section2), 
          getString(R.string.title_section3), 
        }), 
      this); 

考慮到列表項是基於字符串的,我如何更改字體和textcolor?

我已經完成的工作:1-更改Arrayadapter和new String[]類型爲textview。 2試圖將android.R.id.text1更改爲我自己的R.id.textview。 (我的應用支持api 8+) 請講一個簡單的方法,因爲我是android編程的新手。

+0

你看過嗎? [文檔](https://developer.android.com/training/basics/actionbar/styling.html) – Apurva 2015-02-23 17:00:13

+0

樣式是在XML中,所以我可以改變textcolor。字體對我來說更重要。 – David 2015-02-24 10:39:53

回答

0

試試這個

ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.sortby_array, android.R.layout.simple_spinner_item) { 
public View getView(int position, View convertView, ViewGroup parent) { 
View v = super.getView(position, convertView, parent); 
Typeface externalFont=Typeface.createFromAsset(getAssets(), "fonts/your font name here"); 
((TextView) v).setTypeface(externalFont); return v; 
} 
public View getDropDownView(int position, View convertView, ViewGroup parent) { 
View v =super.getDropDownView(position, convertView, parent); 
Typeface externalFont=Typeface.createFromAsset(getAssets(), "fonts/ your font name here"); 
((TextView) v).setTypeface(externalFont); return v; 
} 
}; 
+0

我有R.array的問題!有任何想法嗎?但我仍然認爲這段代碼在'actionBar.setListNavigationCallbacks'方法中不起作用 – David 2015-02-25 06:12:24