안드로이드#11 툴바 타이틀 가운데 정렬
2020. 5. 11. 23:19
먼저 기존에 있는 타이틀을 제거 해야한다
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
그후 xml 에서
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:theme="?attr/actionBarTheme"
app:titleTextAppearance="@style/ToolbarTitleText" >
<TextView
android:id="@+id/textView28"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toolbar Title"
android:layout_gravity="center"
android:textColor="#000000"
android:textSize="15dp"
android:textStyle="bold" />
</androidx.appcompat.widget.Toolbar>
여기서 중요한것은 TextView 의 android:layout_width 를 wrap_content로 해주는것과
android:layout_gravity="center" 로 지정하는것이다
'Programming > Android' 카테고리의 다른 글
안드로이드 #12 ScrollView 안에 RecyclerView 사용하기 (0) | 2020.06.10 |
---|---|
안드로이드#10 툴바 뒤로가기 버튼 만들기 (0) | 2020.05.11 |
안드로이드 #9 AlertDialog 외부화면 클릭, 뒤로가기 클릭시 Dismiss 막기 (0) | 2020.05.08 |
안드로이드 #8 뒤로가기 버튼 두번눌러서 종료 / onBackPressed() (0) | 2020.05.08 |
안드로이드 #7 Layout ClickListener 사용하기 (0) | 2020.05.08 |