2012-08-01 21 views
20

क्या यह शीर्ष पर एक स्पिनर/ड्रॉपडाउन और एक्शन बार में बस नीचे टैब होना संभव है? मैं एक्शन बार के शीर्ष पर स्पिनर का उपयोग व्यू-स्विच कंट्रोलर (यानी टेबल व्यू या चार्ट व्यू) के रूप में करना चाहता हूं, जबकि नीचे दिए गए टैब डेटा की विभिन्न सूचियां दिखाएंगे।क्या एक्शन बार में नेविगेशन के रूप में ड्रॉपडाउन और टैब का उपयोग करना संभव है?

निम्नलिखित स्क्रीन शॉट बिल्कुल मैं क्या हासिल करना चाहते दिखाता है:

enter image description here

यदि यह क्रिया बार में दोनों मोड होने संभव नहीं है, मैं अपनी सामग्री दृश्य के शीर्ष पर एक TabWidget डाल सकता है। हालांकि, अगर मुझे प्रति टैब एक टुकड़ा या एक गतिविधि होनी चाहिए तो मुझे थोड़ा अनिश्चितता है।

+0

मुझे यकीन है कि अगर कार्रवाई बार बहुत लंबा है, तो यह एक और पंक्ति बनाएगा। –

+0

आप ऐसा क्यों करना चाहते हैं? ऐसा लगता है कि उपयोगकर्ताओं को भ्रमित होने की संभावना है। –

+4

@JeffAxelrod quora यह उनके एंड्रॉइड ऐप के लिए करता है। Http://marketingland.com/wp-content/ml-loads/2012/09/quora-android.jpg –

उत्तर

3

संपादित करें:

यह क्रिया बार में नेविगेशन के रूप में लटकती और टैब का उपयोग करना संभव है?

सं ActionBarView में कोड (जहां setNavigationMode (int) कॉल समाप्त होता है) एक स्विच बयान का उपयोग करता है, तो मोड संयुक्त नहीं किया जा सकता है। आप अपने क्रिया बार में एक custom view का उपयोग करें और सामग्री के लिए एक ViewPager इस्तेमाल कर सकते हैं :

कार्रवाई बार नेविगेशन मोड और मेरे पिछले जवाब में से कुछ संयोजन अभी भी एक मान्य विकल्प हालांकि है। व्यूपेजर में प्रत्येक टैब एक टुकड़ा होगा जिसे आप स्पिनर बदलते समय मूल गतिविधि से मैन्युअल रूप से अपडेट कर सकते हैं (दृश्य प्रकार बदलें)।

साइड नोट, ViewPagerExtensions जैसे तृतीय पक्ष पुस्तकालय हैं जो एक्शनबार टैब का उपयोग किए बिना निश्चित टैब उपस्थिति देते हैं।

+0

इस मामले में मुझे NAVIGATION_MODE_LIST से NAVIGATION_MODE_TAB तक एक्शन बार के नेविगेशन मोड को बदलने की आवश्यकता होगी। इससे स्पिनर एक्शन बार गायब हो जाएगा। –

+0

नहीं, इस मामले में एक्शन बार के पास नेविगेशन के साथ कुछ लेना देना नहीं होगा, और टैब एक्शन बार का हिस्सा नहीं होंगे। संपादित करें: उत्तर में मेरा विवरण बदल दिया – roflharrison

+0

क्या आप एक उदाहरण का संदर्भ दे सकते हैं? मुझे यकीन नहीं है कि मैं समझता हूं कि आपका क्या मतलब है। धन्यवाद! –

1
Is it possible to use dropdown AND tabs as navigation in the action bar? 

संभव नहीं डिफ़ॉल्ट बल्ले का उपयोग कर आप कस्टम क्रिया बार दृश्य बना सकते हैं और सेट है कि एक संभव

यह एक कोड

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> 

कोशिश कर सकते हैं lib में

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

TabListener {

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 

} 
1

आप कस्टम कार्रवाई प्रदाता क्रिया बार में एक स्पिनर को प्राप्त करने बना सकते हैं। तो पूरी एक्शन बार बनाने की कोई ज़रूरत नहीं है। ऐसा करके और नेविगेशन मोड के रूप में टैब का उपयोग करें आपका लक्ष्य पूरा हो गया है।

2

यह संभव है। मैं जो दिखाया है उसके लिए एक समान यूआई प्राप्त करने की कोशिश कर रहा था, और तब तक अटक गया जब तक कि मैंने कुछ सरल लेकिन कुछ भ्रमित करने की कोशिश की।

क्या मेरे द्वारा की गई ActionBar के लिए अपने कस्टम दृश्य के रूप में एक स्पिनर सेट किया गया है, और उसके बाद:

ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

यहाँ मैं क्या मतलब का एक उदाहरण है।

टैब्स कोड:

ActionBar actionBar = getActionBar(); 
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 

actionBar.addTab(actionBar.newTab().setText("Today").setTabListener(this)); 
actionBar.addTab(actionBar.newTab().setText("List").setTabListener(this)); 
actionBar.addTab(actionBar.newTab().setText("Month").setTabListener(this)); 

इस गतिविधि के लिए माता-पिता गतिविधि में, मेरे द्वारा की गई इस:

Context contextTheme = new ContextThemeWrapper(this, R.style.ActionBarSpinner); 
Spinner actionBarSpinner = new Spinner(contextTheme); 

// Specify a SpinnerAdapter to populate the dropdown list. 
actionBarSpinnerAdapter = new ActionBarSpinnerAdapter(actionBar.getThemedContext(), dropdownValues); 
actionBarSpinner.setAdapter(actionBarSpinnerAdapter); 

// Set up the dropdown list navigation in the action bar. 
actionBarSpinner.setOnItemSelectedListener(this); 

actionBar.setCustomView(actionBarSpinner); 

यह प्रभावी बनाता है मुझे ActionBar के लिए एक कस्टम दृश्य देता है, लेकिन फिर मैं मुझे इच्छित टैब रखने की अनुमति देने के लिए नेविगेशन मोड को टैब पर सेट कर सकते हैं। प्रत्येक आइटम, और voila पर उपयुक्त घटना श्रोताओं को सेट करें!

+0

मैं ऐसा करने की अनुशंसा नहीं करता हूं। डिवाइस को घूर्णन करते समय, एक्शनबार छुपाया जाता है और कस्टम दृश्य टैब के दाईं ओर रखा जाता है, जो कम से कम मेरे मामले में नहीं है जो मैं चाहता हूं। इसके अलावा, आपको अपना उत्तर पूरा करने के लिए ActionBarSpinner शैली प्रदान करने की आवश्यकता होगी। और, आपको शीर्षक को छिपाने की जरूरत है, अन्यथा आपका स्पिनर शीर्षक के दाईं ओर रखा गया है: actionBar.setDisplayShowTitleEnabled (false); – Maragues