마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

ActionBar의 타이틀 관련 질문입니다.

0 추천

앱의 액션바에

<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>

xml 코드는 이런식입니다.

여기에 TextView를 참조하게 해서 타이틀을 지정을 해놨는데요.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:orientation="vertical">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:text="@string/app_name"
        android:textColor="#ffffff"
        android:textSize="24sp" />
</LinearLayout>

gravity를 센터로 줬는데도 좌측으로 붙어 있습니다.

 

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setCustomView(R.layout.toolbar_label);

검색한 링크를 참고로 Activity java 코드는 이렇게 해놨습니다.

타이틀을 조정할 화면의 내용은

|햄버거이미지    | 타이틀 센터 |                     |

 

|뒤로가기이미지   | 타이틀 센터 |                     |

 

이런식으로 나왔으면 좋겠습니다.

브레인토스트 (880 포인트) 님이 2016년 4월 6일 질문

1개의 답변

0 추천
 
채택된 답변
자체해결했습니다~!~!!!!!!!!!!!!!!!!!!!!
브레인토스트 (880 포인트) 님이 2016년 4월 6일 답변
어떻게 해결하셨나요??
...