2013-12-23 48 views
0

我有延伸片段活动活动......在我想设置自定义操作吧...我这样尝试了..但是这是不工作如何在片段活动中的ActionBar中使用自定义视图?

public class MainActivity extends FragmentActivity 
{ 
bar = getActionBar(); 
      bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST); 
      bar.setBackgroundDrawable(new ColorDrawable(Color 
        .parseColor("#0194bf"))); 

      mInflater = LayoutInflater.from(this); 
      mCustomView = mInflater.inflate(R.layout.actionbar_view, null); 
      TextView txtTitle = (TextView) mCustomView 
        .findViewById(R.id.action_title); 
      txtTitle.setText("Recipe List"); 
      txtTitle.setTextSize(22); 
      txtTitle.setTextColor(Color.parseColor("#ffffff")); 
      bar.setCustomView(mCustomView); 
} 

这是我的自定义视图

<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/action_title" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center|left" 
    android:textIsSelectable="false" 
    android:paddingLeft="5dip" 
    android:textStyle="bold" 
    android:typeface="serif" /> 
+0

“这是行不通的”不是一个很好的线描述你的问题。发布你的logcat。所以我们会理解这个问题。 – Avijit

+2

bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);在你的代码中加上这个 –

+0

Thanx for answer ... @ Karan –

回答

1

不要忘了此行:

actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

相关问题