0

내 앱에 8 개의 탭이 있으며, 끝까지 도달 할 때까지 스크롤해야하는 마지막 4 개의 탭에 더 쉽게 액세스하고 싶습니다.뷰 페이지 슬라이딩 탭의 탭에 드롭 다운을 추가하는 방법은 무엇입니까?

재료 디자인 지침에 따르면 마지막 탭으로 "more"옵션을 제공하여 탭에서 드롭 다운을 사용할 수 있으며 사용자가 드롭 다운 항목을 선택하면 해당 항목이 마지막에서 두 번째 탭에 표시되고 강조 표시됩니다 선택한 탭으로.

어떻게해야합니까? 이 작업을 수행하는 방법에 대한 문서가 없습니다. 이미지 만 제공됩니다.

Here's the link to material design guidelines for tabs

Here's an image of tabs with an option "more"

답변

0
그들이이 road.Here의 내가 발견 무엇에 갈 것을 결정하는 경우에 나는, 누군가의 시간을 절약 할 수있는 내 자신의 질문에 대답합니다

: - 나는 TabLayout에서 오버 플로우 페이지 매김에 대한 탭에서 비슷한 질문을 게시했다

@ianhanniballake의 대답을 받았다. 그는이 기능들이 데스크톱 탭 용이고 TabLayout에서는 지원되지 않는다고 언급했다.

Here's the link to the question

0

나는 PopupMenu를 사용하도록 추천 할 것입니다. 사용하기 쉽고 멋지게 보입니다. 여기

내가 그것을 사용하는 방법 예는 다음과 같습니다

활동

View view = findViewById(R.id.action_settings); 

      LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      View popupView = layoutInflater.inflate(R.layout.popup, null); 
      final ListView listView = (ListView) popupView.findViewById(R.id.listView); 

      String[] functions = {getString(R.string.shareScreenshot), getString(R.string.shareDatei), getString(R.string.shareXML)}; 

      ListAdapter adapter = new CustomPopupAdapter(this, functions, listView); 
      listView.setAdapter(adapter); 

      Display display = (this.getWindowManager().getDefaultDisplay()); 
      Point size = new Point(); 
      display.getSize(size); 
      int width = size.x; 
      //int height = size.y; 

      Resources resources = this.getResources(); 
      int navigationBarHeight = 0; 
      int statusbarHeight = 0; 
      int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android"); 
      if (resourceId > 0) { 
       navigationBarHeight = resources.getDimensionPixelSize(resourceId); 
      } 

      resourceId = resources.getIdentifier("status_bar_height", "dimen", "android"); 
      if (resourceId > 0) { 
       statusbarHeight = resources.getDimensionPixelSize(resourceId); 
      } 

      final PopupWindow popupWindow = new PopupWindow(this); 
      popupWindow.setContentView(popupView); 
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
       popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(this, R.drawable.shadow_02327)); 
      } else { 
       popupWindow.setBackgroundDrawable(ContextCompat.getDrawable(this, R.drawable.shadow_02327)); 
      } 
      popupWindow.setWidth(width); 
      popupWindow.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); 
      popupWindow.setOutsideTouchable(true); 
      popupWindow.setFocusable(true); 
      popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, 0, navigationBarHeight + statusbarHeight); 

      listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
       @Override 
       public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 

        //Click handle 
       } 
      }); 
     } 

어댑터

public class CustomPopupAdapter extends ArrayAdapter { 

      private String[] option; 
      ListView owner; 


     public CustomPopupAdapter(Context context, String[] option, ListView owner) { 
      super(context, R.layout.custom_row_settings, option); 
      this.option = option; 
      this.owner = owner; 
     } 

     @Override 
     public View getView(int pos, View view, ViewGroup parent) { 
      LayoutInflater inflater = LayoutInflater.from(getContext()); 

      View customView = inflater.inflate(R.layout.popup_row_image_text, parent, false); 

      ImageView iv = (ImageView) customView.findViewById(R.id.imageView); 
      TextView tv = (TextView) customView.findViewById(R.id.textView); 
      tv.setText(option[pos]); 


      switch (pos) { 
       case 0: 
        iv.setImageResource(R.drawable.ic_photo_camera_grey_24dp); 
        break; 
       case 1: 
        iv.setImageResource(R.drawable.ic_insert_drive_file_grey_24dp); 
        break; 
       case 2: 
        iv.setImageResource(R.drawable.ic_code_grey_24dp); 
        break; 
       case 3: 
        iv.setImageResource(R.drawable.ic_move_to_inbox_grey_24dp); 
        break; 
      } 

      return customView; 
     } 
    } 

popup.xml을

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:padding="5dp" 
    android:background="@color/white"> 

    <ListView 
     android:id="@+id/listView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 

    </ListView> 

</RelativeLayout> 
+0

은 어떻게 마지막 탭 팝업 메뉴에서 선택한 옵션을 가져오고 선택한 탭으로 보일 수 있는가? –

+0

예제의 앵커가 null입니다. 원하는 탭으로 변경하십시오! 그럼 당신은 그것을 가지고 있어야합니다 :) – XxGoliathusxX

+0

이것은 내 질문에 대답하지 않는다, 나는 드롭 다운으로 탭을 설정하는 방법을 알고 싶다, 나는 팝업 메뉴를 만드는 방법을 알고있다. 그러나 당신이 탭에서 팝업 메뉴를 사용하도록 제안한다면 탭과 관련된 코드로 어떻게 설명하십시오. –

관련 문제