Is it possible to use dropdown AND tabs as navigation in the action bar?
バットを使用したデフォルトのライブラリでは不可能 カスタムアクションバービューを作成し、それを可能に設定することができます
この1つのコードを試してください
action_bar.xml
<LinearLayout
android:id="@+id/actionbar_linearLayout_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="2dip"
android:gravity="right" >
<ImageView
android:id="@+id/actionbar_imageView_menu_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dip"
android:padding="8dp"
android:src="@drawable/button_search_selector" />
<ImageView
android:id="@+id/actionbar_imageView_menu_myaccount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dip"
android:padding="8dp"
android:src="@drawable/button_myaccount_selector" />
<ImageView
android:id="@+id/actionbar_imageView_menu_settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dip"
android:padding="8dp"
android:src="@drawable/button_settings_selector" />
</LinearLayout>
<LinearLayout
android:id="@+id/actionbar_linearLayout_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/actionbar_linearLayout_menu" >
<Spinner
android:id="@+id/actionbar_spi_menu"
style="@style/MenuSpinnerTextViewItem"
android:layout_width="80dip"
android:layout_height="34dip"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="6dip"
android:background="@drawable/spinner_bg"
android:paddingLeft="3dip"
android:spinnerMode="dropdown"
android:visibility="gone" />
<com.smartdeal.util.SmartDealTextView
android:id="@+id/actionbar_txt_title"
style="@style/Style_Text_Bold"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="4dip"
android:gravity="left"
android:padding="5dip"
android:text="Smart Deal"
android:textColor="@android:color/white"
android:textSize="18dip" />
</LinearLayout>
<LinearLayout
android:id="@+id/actionbar_linearLayout_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="@drawable/serch_bg"
android:visibility="gone" >
<ImageView
android:id="@+id/actionbar_imageView_searchMenu_search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/search_icon_selected" />
<EditText
android:id="@+id/actionbar_edt_searchMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_weight="1"
android:background="@null"
android:singleLine="true"
android:textColor="@android:color/white"
android:textSize="18dip" >
</EditText>
<ImageView
android:id="@+id/actionbar_imageView_searchMenu_cancel"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="5dip"
android:src="@drawable/search_cancel" />
</LinearLayout>
BaseActivity.java
{
final ActionBar ab = getSupportActionBar();
ab.setDisplayHomeAsUpEnabled(true);
final LayoutInflater inflater = (LayoutInflater) getSystemService("layout_inflater");
ab.setDisplayShowTitleEnabled(false);
// ab.setTitle("Settings");
View view = inflater.inflate(R.layout.actionbar_view, null);
linLayoutMenu = (LinearLayout) view
.findViewById(R.id.actionbar_linearLayout_menu);
linLayoutSearch = (LinearLayout) view
.findViewById(R.id.actionbar_linearLayout_search);
linLayoutTitle = (LinearLayout) view
.findViewById(R.id.actionbar_linearLayout_title);
txtTitle = (TextView) view.findViewById(R.id.actionbar_txt_title);
spiMenu = (Spinner) view.findViewById(R.id.actionbar_spi_menu);
menuSearch = (ImageView) view
.findViewById(R.id.actionbar_imageView_menu_search);
menuMyaccount = (ImageView) view
.findViewById(R.id.actionbar_imageView_menu_myaccount);
menuSettings = (ImageView) view
.findViewById(R.id.actionbar_imageView_menu_settings);
menuSearchCancel = (ImageView) view
.findViewById(R.id.actionbar_imageView_searchMenu_cancel);
menuSearch.setOnClickListener(this);
menuMyaccount.setOnClickListener(this);
menuSettings.setOnClickListener(this);
menuSearchCancel.setOnClickListener(this);
if (this instanceof HistoryActivity) {
txtTitle.setVisibility(View.GONE);
spiMenu.setVisibility(View.VISIBLE);
List<String> list = new ArrayList<String>();
list.add("History");
list.add("Activity");
MenuListAdapter menuList = new MenuListAdapter(this, list);
spiMenu.setAdapter(menuList);
} else {
txtTitle.setVisibility(View.VISIBLE);
spiMenu.setVisibility(View.GONE);
}
ab.setCustomView(view);
ab.setDisplayShowCustomEnabled(true);
}
ViewActivity.java
タブリスナー {
private ListView historyList;
private ArrayList<String> list;
LinearLayout linLayoutHistory, linLayoutActivity;
private ActionBar actionBar;
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.....);
initComponent();
}
private void initComponent() {
// setActionBarHomeUpAsEnable(true);
linLayoutActivity = (LinearLayout) findViewById(R.id.history_activity_linLayout_activity);
linLayoutHistory = (LinearLayout) findViewById(R.id.history_activity_linLayout_history);
historyList = (ListView) findViewById(R.id.history_activity_listView);
list = new ArrayList<String>();
spiMenu.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab month_tab = actionBar.newTab()
.setText(getResources().getString(R.string.tab_month))
.setTabListener(this);
ActionBar.Tab year_tab = actionBar.newTab()
.setText(getResources().getString(R.string.tab_year))
.setTabListener(this);
ActionBar.Tab all_tab = actionBar.newTab()
.setText(getResources().getString(R.string.tab_all))
.setTabListener(this);
actionBar.addTab(month_tab);
actionBar.addTab(year_tab);
actionBar.addTab(all_tab);
return super.onCreateOptionsMenu(menu);
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
// TODO Auto-generated method stub
}