15

私の問題は、nav-drawerアイコンとツールバーのタイトルの間の余分なスペースです。サンプル画像は以下の通りです:ナビゲーションアイコンとツールバーのタイトルの間のギャップを減らす方法は?

spacing between nav-drawer icon and title

spacing between back icon and toolbar

ツールバーのXMLビューは、私は以下のコードを使用してこの問題を解決しようとした

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

ですが、何の変化も起こりませんでした。

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_home); 
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    setSupportActionBar(toolbar); 

    //toolbar.setTitleMarginStart(0); 
    toolbar.setTitleMarginStart(-8); 
} 

この問題を解決する方法はありますか?

+0

カスタムアクションバーを作成し、好きなように項目を表示することができます。 – JuLes

+1

これはなぜ問題ですか?これはプラットフォーム開発者による設計上の決定であり、これがGoogleのAndroid用アプリの外観です。 – Egor

+0

@egor 2/3文字以上を表示できる場合は、タイトルが長くなることがあります。小さなものを試してみることも楽しいです。 –

答えて

28

ToolBar

app:contentInsetLeft="0dp" 
app:contentInsetStart="0dp" 
app:contentInsetStartWithNavigation="0dp" 

を追加します。

完全なコード:

<android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="?attr/colorPrimary" 
     app:titleTextAppearance="@style/Toolbar.TitleText" 
     app:popupTheme="@style/AppTheme.PopupOverlay" 
     app:contentInsetLeft="0dp" 
     app:contentInsetStart="0dp" 
     app:contentInsetStartWithNavigation="0dp" /> 
+0

@Sagar Chapagainはそれを知ってうれしいです。 – Ironman

+1

それは良い解決策です。本当に役に立ちました。 –

+0

https://stackoverflow.com/questions/47207491/remove-padding-between-hamburger-icon-and-toolbar ..まだギャップがあります。 \t @Sagar Chapagain –

関連する問題