2017-12-14 4 views
1

私は取得しています何:アンドロイドでリップルではなく正方形の効果を得るにはBottomNavigationView?

enter image description here

を私が取得することを目指しています何:

enter image description here

私はbuild.graldeにこれを追加することによって、最初の1つを得ました

compile 'com.android.support:design:25.3.1' 
compile 'com.github.ittianyu:BottomNavigationViewEx:1.2.4' 

これは私のレイアウトxml:

<com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx 
      android:id="@+id/bottomView" 
      android:layout_height="wrap_content" 
      android:layout_width="match_parent" 
      android:layout_gravity="bottom" 
      app:menu="@menu/bottom_nav_items" 
      android:background="#f8f8f8"/> 

答えて

2

BottomNavigationViewのカスタムレイアウトを使用します。レイアウトのクリック可能な親には、属性android:background = "?selectableItemBackground"が含まれている必要があります。 以下はその例です。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:background="?selectableItemBackground" 
android:clickable="true" 
android:duplicateParentState="true" 
android:gravity="center" 
android:orientation="vertical"> 

<ImageView 
    android:id="@+id/img" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@mipmap/ic_launcher" /> 


<TextView 
    android:id="@+id/txt" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/sel" /> 

これはキットカットと以下正常矩形上記およびキットカットに長方形のリップルの経験を与えます。あなたがリップルを望んでいないなら(すべてのアンドロイド版で)。セレクタを背景として使用します。

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:state_pressed="true"> 
    <shape android:shape="rectangle"> 
     <solid android:color="#4C000000" /> 
    </shape> 
</item> 
<item> 
    <shape android:shape="rectangle"> 
     <solid android:color="@color/transparent" /> 
    </shape> 
</item> 

代わりにこれを使用してください。

<android.support.design.widget.BottomNavigationView 
    android:id="@+id/bottomNavigation" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    app:itemBackground="?selectableItemBackground" 
    /> 
+0

は、最初のものを試しましたが、それはうまくいきませんでした、_、 – Krestek

+0

そして、はい、私は – Krestek

+0

は今それを使って長方形の波及効果を目指しています。それは仕事をshuld。私は今自分のことをテストすることはできませんが、試してみてください。 – ADM

関連する問題