2016-06-23 18 views
5

W nowym Androidzie 24 stwierdziłem, że ikona icon i tytuł na pasku aplikacji mają szerszą wyściółkę i nie mogę znaleźć żadnej metody Rozwiąż to.Pasek wypełnienia/spacji między ikoną i tytułem (Android 24)

przykład:

Additional space between icon and title

MainActivity.java:

public class MainActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
     setSupportActionBar(toolbar); 
     getSupportActionBar().setTitle("Testing"); 
     getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
     getSupportActionBar().setDisplayShowHomeEnabled(true); 

     FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 
     fab.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 
         .setAction("Action", null).show(); 
      } 
     }); 
    } 

} 

Główny układ aktywny (xml)

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fitsSystemWindows="true" 
    tools:context="house.appbartesting.MainActivity"> 

    <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="?attr/actionBarSize" 
     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" 
     android:src="@android:drawable/ic_dialog_email" /> 

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

.....

Odpowiedz

17

Możesz dodać ten atrybut na pasku narzędzi, aby uniknąć dopełnienia.

app:contentInsetStartWithNavigation="0dp" 
+0

To zdarzyło się mnie, kiedy zmodernizowane moją wersję SDK od 23 do 24 adn to naprawił. Dziękuję Ci. –

2
Use below code to remove the extra spacing generated between back arrow and title 
for Android 24 (buildToolsVersion "24"/targetSdkVersion 24) 

Do not remove following lines - 

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

Code - 

<android.support.v7.widget.Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/red" 
    android:minHeight="?attr/actionBarSize" 
    app:contentInsetLeft="0dp" 
    app:contentInsetStart="0dp" 
    app:contentInsetStartWithNavigation="0dp" 
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" 
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

</android.support.v7.widget.Toolbar> 
Powiązane problemy