2016-10-01 6 views
0

私は4つのアイコンで私のアプリにツールバーウィジェットを持っていて、これらのアイコン間のスペースサイズを同じに変更したいと思います。 current designAndroid上のウィジェットツールバーアイコン間のスペースサイズを変更する方法は?

このようになり: wanted design

menu.xml

<?xml version="1.0" encoding="utf-8"?> 

<item 
    android:id="@+id/action_home" 
    android:orderInCategory="100" 
    android:icon="@drawable/white_home" 
    android:title="@string/action_settings" 
    app:showAsAction="always" /> 

<item 
    android:id="@+id/action_profile" 
    android:orderInCategory="101" 
    android:icon="@drawable/white_profile" 
    android:title="@string/action_settings" 
    app:showAsAction="always" /> 

<item 
    android:id="@+id/action_inbox" 
    android:orderInCategory="102" 
    android:icon="@drawable/white_inbox" 
    android:title="@string/action_settings" 
    app:showAsAction="always" /> 

<item 
    android:id="@+id/action_contacts" 
    android:orderInCategory="103" 
    android:icon="@drawable/white_contacts" 
    android:title="@string/action_settings" 
    app:showAsAction="always" /> 

この

フォーム事前に

app_bar_main.xml

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 

    <android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/colorPrimary" 
     app:popupTheme="@style/AppTheme.PopupOverlay" /> 

</android.support.design.widget.AppBarLayout> 

<include layout="@layout/content_main" /> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|end" 
    android:layout_margin="@dimen/fab_margin" 
    app:srcCompat="@drawable/ic_fab_plus" 
    app:backgroundTint="@color/colorPrimary" /> 

感謝。

+0

ここ –

+0

ポストあなた*レイアウト*コードをあなたのxmlファイルをSENSしてください。 –

答えて

0

ここには、ツールバーをハックしてアイテムを幅いっぱいに配置する方法のexampleがあります。あなたは、アクションの間のスペースを変更することができるようにしたい場合

を更新し

@Override 
public void addView(View child, ViewGroup.LayoutParams params) { 
    if (child instanceof ActionMenuView) { 
     params.width = LayoutParams.MATCH_PARENT; 
    } 
    super.addView(child, params); 
} 

主なポイントは、あなたがaddViewメソッドをオーバーライドする独自のツールバーの相続を宣言する必要があるということですxmlを使用してアイテムを拡張したくない場合は、Toolbar.classのツールバーを使用してください(私はあなたにsetSupportActionBar()と呼んでください)can chang電子styles.xmlリソースファイルでアプリケーションのテーマ:カリルJomaa @

<style name="AppTheme" parent="AppBaseTheme"> 
    <item name="android:actionButtonStyle">@style/MyActionButtonStyle</item> 
</style> 

<style name="MyActionButtonStyle" parent="AppBaseTheme"> 
    <item name="android:minWidth">20dp</item> 
    <item name="android:padding">0dp</item> 
</style> 
+0

Michaelさん、ありがとうございましたが、私はXMLレイアウトを編集したり、カスタムツールバースタイルを作成したりできますか? –

+0

@KhalilJomaa編集の回答 –

+0

@KhalilJomaaそれはあなたを助けましたか? –

関連する問題