2015-02-23 118 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