2016-04-23 7 views
-1

enter image description hereActionBar schneidet Links-Rechts-Seite ab?

Bitte Schauen Sie sich unten Bild,

Und hier ist der Code:

ActionBar actionBar = getSupportActionBar(); 
    if (actionBar != null) { 

     actionBar.setDisplayShowHomeEnabled(false); 
     actionBar.setDisplayShowTitleEnabled(false); 
     actionBar.setDisplayShowCustomEnabled(true); 

     View view = getLayoutInflater().inflate(R.layout.action_bar, null); 

     ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT, 
       ActionBar.LayoutParams.MATCH_PARENT); 
     actionBar.setCustomView(view, layoutParams); 
     view.getLayoutParams().width = ActionBar.LayoutParams.MATCH_PARENT; 
     Toolbar parent = (Toolbar) view.getParent(); 
     parent.setContentInsetsAbsolute(0, 0); 


     TypedValue tv = new TypedValue(); 
     if (getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) { 
      int actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics()); 
      View bottom = findViewById(R.id.bottomLayout_FrameLayout_LoginActivity); 
      bottom.getLayoutParams().height = actionBarHeight; 

     } 
     tvTitleActionBar = (TextView) actionBar.getCustomView().findViewById(R.id.title_TextView_ActionBar); 

     getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
    } 

R.layout.action_bar:

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/head_bottom_blue_color"> 

    <ImageView 
     android:id="@+id/openSlideMenu_ImageView_ActionBar" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:clickable="true" 
     android:src="@android:drawable/ic_menu_sort_by_size" 
     android:visibility="gone" /> 

    <TextView 
     android:id="@+id/title_TextView_ActionBar" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:textAppearance="@android:style/TextAppearance.Medium" 
     android:textColor="@android:color/white" 
     android:textStyle="bold" /> 
</RelativeLayout> 
+0

Warum downvoted? –

Antwort

0

In diese Arten

<style name="MyActionBar" parent="@style/Base.Widget.AppCompat.ActionBar"> 
    <item name="contentInsetStart">0dp</item> 
    <item name="contentInsetEnd">0dp</item> 
</style> 

und es dann in Ihrem AppTheme wie folgt verwenden

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
<!-- Customize your theme here. --> 
<item name="android:actionBarStyle">@style/MyActionBar</item> 

Hoffe, es hilft

0

Das sieht aus wie das gleiche Problem adressiert here - siehe die vorgeschlagenen Antworten - vor allem th Die ausgewählte Antwort ODER die Antwort von Amrut Bidri vorgeschlagen (in seinem Fall fügen Sie ein paar Zeilen). Hoffentlich löst das dein Problem.

Verwandte Themen