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" />
「這是行不通的」不是一個很好的線描述你的問題。發佈你的logcat。所以我們會理解這個問題。 – Avijit
bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);在你的代碼中加上這個 –
Thanx for answer ... @ Karan –