2016-07-24 10 views
12

マイツールバーツールバーのタイトルからパディングを削除するにはどうすればいいですか?

My toolbar

Googleは、私は、不要なパディングを削除することができますどのようにツールバー

GooglePlay toolbar

を再生しますか?

私のツールバーが フラグメントで私のコードの断片内にある:

public void setUpToolbar(Toolbar toolbar, String title, @DrawableRes int resId) { 
    toolbar.setTitle(title); 
    ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar); 
    ActionBar ab = ((AppCompatActivity) getActivity()).getSupportActionBar(); 
    ab.setHomeAsUpIndicator(resId); 
    ab.setDisplayHomeAsUpEnabled(true); 
} 

XMLでの私のツールバー:

<android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      app:layout_collapseMode="pin" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 
+0

http://stackoverflow.com/aを/ 38302389/1462770 – Amir

+4

app:contentInsetStartWithNavigation = "0dp" – Amir

答えて

2

あなたのコードでこれを試してみてください:

ActionBar actionBar = getSupportActionBar(); 
actionBar.setDisplayShowHomeEnabled(false); 
actionBar.setDisplayShowCustomEnabled(true); 
actionBar.setDisplayShowTitleEnabled(false); 
View customView = getLayoutInflater().inflate(R.layout.main_action_bar, null); 
actionBar.setCustomView(customView); 
Toolbar parent =(Toolbar) customView.getParent(); 
parent.setContentInsetsAbsolute(0,0); 
+0

いいえ、役に立たなかった – gape

+0

@gape今すぐ試してみましょう私は知っている –

7

ジャスト追加しますあなたのツールバーの

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

それはアプリを追加する

1

てみてください動作するはずです:contentInsetLeft:

<android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      app:layout_collapseMode="pin" 
      app:contentInsetLeft="0dp" 
      app:contentInsetStart="0dp" 
      app:popupTheme="@style/AppTheme.PopupOverlay" /> 
9

使用このツールバーのXMLタグ内

app:contentInsetStartWithNavigation="0dp" 
+0

これは私のために働いたものです。ありがとうございました!! –

+0

大歓迎:) –

関連する問題