2017-02-15 7 views
3

TabLayout 아래에 줄을 추가하는 데 문제가 있습니다 만 선택자 줄 뒤에 있어야합니다. 이 같은이어야합니다TabLayout 아래에 한 줄 추가하기

Exemple

가 이미 사용자 정의보기를 추가하려고했으나 각 탭은 내부의 여백이 너무 밖으로 일을하지 않았다.

어떤 아이디어가 있습니까?

내가 지금 무엇을 가지고 있습니다 : 여기

current_tablayout

는 어떻게 XML에 추가 해요 :

<android.support.design.widget.TabLayout 
    android:id="@+id/tabs" 
    android:layout_width="match_parent" 
    android:layout_height="60dp" 
    app:tabBackground="@color/white" 
    app:tabIndicatorColor="@color/colorAccent" 
    app:tabTextColor="@color/white"/> 

를이 내가 코드를 통해 뭘하는지입니다 :

private void configureTabLayout() { 
    TabLayout.Tab tabHome = mTabLayout.newTab().setIcon(R.drawable.ic_home_cinza); 
    TabLayout.Tab tabEmprestimos = mTabLayout.newTab().setIcon(R.drawable.ic_emprestimos_cinza); 
    TabLayout.Tab tabPersonal = mTabLayout.newTab().setIcon(R.drawable.ic_usuario_cinza); 

    View root = mTabLayout.getChildAt(0); 
    if (root instanceof LinearLayout) { 
     ((LinearLayout) root).setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE); 
     GradientDrawable drawable = new GradientDrawable(); 
     drawable.setColor(getResources().getColor(R.color.silver)); 
     drawable.setSize(2, 1); 
     ((LinearLayout) root).setDividerPadding(10); 
     ((LinearLayout) root).setDividerDrawable(drawable); 
    } 

    mTabLayout.addTab(tabHome); 
    mTabLayout.addTab(tabEmprestimos); 
    mTabLayout.addTab(tabPersonal); 
    mTabLayout.setTabGravity(TabLayout.GRAVITY_FILL); 
} 
+0

귀하의 xml은 무엇입니까? 예상 출력을 추가 할 수 있다면 –

+0

실제로 매우 간단합니다. 질문에 –

+0

*을 추가 할 것입니다. 그러나 각 탭에는 몇 개의 여백이 있습니다. * 탭 내부 또는 탭 버튼 바로 아래에 해당 라인을 추가 하시겠습니까? –

답변

5

Drawable 폴더에 xml

당신의 TabLayout

<android.support.design.widget.TabLayout 
     android:background="@drawable/background" 
     android:id="@+id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="60dp" 
     app:tabIndicatorColor="@color/colorAccent" 
     app:tabTextColor="@color/white"/> 

값을 변경하고 필요에 따라 색상이 16,

background.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 

    <item android:top="-10dp" android:right="-10dp" android:left="-10dp"> 
     <shape xmlns:android="http://schemas.android.com/apk/res/android" 
      android:shape="rectangle"> 
      <solid android:color="#1bd4f6" /> 
      <stroke 
       android:width="2dp" 
       android:color="#0288D1" /> 
     </shape> 
    </item> 

</layer-list> 

를 설정!

출력 :

enter image description here

+0

@Felipe Castilhos 확인하셨습니까? –

+1

트릭을 한 덕분에 @Charu!! –

+0

분명히 tablayout 대신에 탭에 배경을 설정하려고 잘못했습니다. –

2

이 작업을 시도 할 수 있습니다. 솔루션

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <android.support.design.widget.TabLayout 
     android:id="@+id/tabs" 
     android:layout_width="match_parent" 
     android:layout_height="60dp" 
     app:tabBackground="@color/white" 
     app:tabIndicatorColor="@color/colorAccent" 
     app:tabIndicatorHeight="2.5dp" 
     app:tabTextColor="@color/white"/> 

    <View 
     android:layout_width="match_parent" 
     android:layout_height="2.5dp" 
     android:layout_gravity="bottom" 
     android:background="#c6c6c6" /> 

</FrameLayout> 
+0

내가 그랬어, 회색 라인을 보여줍니다 TabLayoutSelector. 하지만 답장을 보내 주셔서 감사합니다. –