툴바의 가운데에 글자나 이미지가 오게 만들어야하는데, 이미지뷰와 텍스트뷰를 넣어도 정중앙으로 맞춰지지가 않았다.
남들은 라이브러리를 쓰는건가 싶어서 이리저리 찾아보니 그런 거 아니고 ViewGroup으로 감싼 거였다 -_-;;;
그것도 모르고 종일 꼼수 부리느라 시간을 헛되이 보냈다니 ㅠㅠ
<android.support.design.widget.AppBarLayout android:id="@+id/app_bar" android:layout_width="match_parent" android:layout_height="wrap_content"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="?attr/colorPrimary" android:minHeight="?attr/actionBarSize" app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:src="@mipmap/ic_launcher"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="HOME" android:textColor="#fff" android:textSize="20sp"/> </FrameLayout> </android.support.v7.widget.Toolbar> </android.support.design.widget.AppBarLayout>
코드에서는
getSupportActionBar().setDisplayShowTitleEnabled(false);
이것만 해주면 된다.
나머지는 원래 하던데로 하면 된다.
좌우에 메뉴아이템이나 이전 화면으로 가는 버튼이 생겨도 가운데로 표시된다.