2016-07-26 2 views
0

툴바의 아이콘을 가운데 정렬하려면 어떻게합니까? 이미 레이블을 제거했습니다 getSupportActionBar().setDisplayShowTitleEnabled(false); 내 도구 모음에 대한 XML 파일을 만드는 것이 가장 좋습니다.툴바의 아이콘 정렬

답변

1

예, 도구 모음에서 일부 레이아웃을 만들고 레이아웃에서 다른 컨트롤 (보기)을 가질 수 있습니다.

툴바는 다른 레이아웃과 비슷하며 중첩 할 수 있습니다. .

mToolbar.getViewTreeObserver() addOnGlobalLayoutListener (새 ViewTreeObserver.OnGlobalLayoutListener() { @Override 공공 무효 onGlobalLayout() { 이미지 뷰의 이미지 뷰 = (이미지 뷰를 다음과 같이 프로그래밍 방식

<android.support.v7.widget.Toolbar 
     android:id="@+id/toolbar_actionbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     app:layout_scrollFlags="scroll|enterAlways"> 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="?android:attr/actionBarSize"> 
      <TextView 
       android:id="@+id/title" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" 
       android:layout_centerVertical="true" 
       android:text="@string/news"/> 
     </RelativeLayout> 
    </Toolbar> 
1

당신은 그것을 할 수 있습니다) mToolbar.findViewById (R.id.logo) 경우 (mToolbar == NULL) { 창; } INT toolbarWidth mToolbar.getWidth =(); INT IMAGEWIDTH imageView.getWidth =();imageView.setX (toolbarWidth-imageWidth)/2); } }); layout_toolbar.xml 사용자 정의 :

<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" 
     style="@style/Toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="@dimen/toolbar_height"                 
     android:background="@drawable/toolbar_background" 
     android:focusable="false"         
     app:titleTextAppearance="@style/AppTheme.Toolbar.Title"> 
     <ImageView 
      android:id="@+id/logo" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/toolbar_logo"/> 

</android.support.v7.widget.Toolbar>