我有活动,它扩展了片段活动......因为我想设置自定义操作栏...我试过这种方式..但这不起作用
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 :(得分:2)
别忘了这句话:
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);