4

에서 탐색 항목에 여백을 추가 like :내가 같이 인스턴스화 <code>BottomNavigationView</code>이 BottomNavigationView

<vector xmlns:android="http://schemas.android.com/apk/res/android" 
    android:width="24dp" 
    android:height="24dp" 
    android:viewportHeight="24.0" 
    android:viewportWidth="24.0"> 
    <path 
     android:fillColor="#FFFFF0" 
     android:pathData="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z" 
     android:strokeColor="#FFFFF0" 
     android:strokeWidth="1" /> 
</vector> 

위에서 볼 수 있듯이 navigat의 버튼 주위에는 테두리가 있습니다. 그러나 이온 아이템은 국경이 서로 닿아 있습니다. 따라서 나는 메뉴 버튼 사이에 여백을 추가하고 싶습니다. 어떻게해야합니까? 당신은 또한 스크린 샷에서 볼 수 있듯이

enter image description here

, 나는 모드로 이동 방지하고 있습니다. 전화로이 작업을 수행합니다.

BottomNavigationViewHelper.removeShiftMode(navigationView); 

here 코드를 사용하십시오. 버튼 주위

경계는 다음과 같이 추가되었습니다 stateListDrawable 다른 메뉴 버튼을 누를 때 변하는 StateListDrawable 지칭

int stateListDrawable = drawableStateLists.get(currentFragment); 
navigationView.setItemBackgroundResource(stateListDrawable); 

있다. StateListDrawable 예를 들어, 결과적으로이 같은 XML 형태를 참조하는 XML 선택을 의미한다 : - 삽입

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <corners android:radius="5dp"/> 
    <stroke 
     android:width="2dp" 
     android:color="@color/intro"/> 
</shape> 
+0

어떻게 그 테두리를 추가 했습니까? – azizbekian

+0

@azizbekian 제 편집을 참조하십시오. – kalabalik

답변

2

주의 깊게 검사 및 소스와 실험 후, 나는 가장 기본적이고 합법적 인 해결책을 함께했습니다 드로어 블 그 자체. 당신은 출력

<?xml version="1.0" encoding="utf-8"?> 
<inset xmlns:android="http://schemas.android.com/apk/res/android" 
    android:insetLeft="10dp" 
    android:insetRight="10dp"> 
    <shape android:shape="rectangle"> 
     <corners android:radius="5dp" /> 
     <stroke 
      android:width="2dp" 
      android:color="#ffffff" /> 
    </shape> 
</inset> 

다음거야 :

이 같은 XML 드로어 블 선언 한 데

enter image description here

은 내가 처음 프로그래밍 해결책을 찾기 위해 노력을하지만,이되지 않습니다 밝혀 저것을하기 위하여 다량 솔기가 존재한다 (적어도 that're 나의 발견이다). 정확히 말하면 각 항목의 레이아웃 매개 변수는 ViewGroup.LayoutParams의 인스턴스입니다. 항목이 ViewGroup.MarginLayoutParams으로 배치 된 경우 각 항목에 개별적으로 여백을 설정할 수 있습니다. 그때까지는 배경 drawable xml을 대신 삽입해야합니다.

+0

이 작업 중입니다! – kalabalik

관련 문제