2017-04-18 2 views
-3

enter image description here센터 작업 표시 줄을 정렬하는 방법

나는 활동 제목을 설정하는 두 가지 방법이 있다는 것을 알고 있습니다. 한 가지 방법은 android : label = "@ string/app_name"과 같은 android manifest에서 설정하는 것입니다. 두 번째는 프로그래밍 방식으로 setTitle ("Hello World!")과 같은 활동 클래스에서 설정됩니다. 두 방법 모두 왼쪽에 위치하지만 어떻게 센터에 배치 할 수 있습니까? 활동 태그 내부 매니페스트 파일에

+0

툴바를 사용하는 경우 텍스트 표제 어테 렐 런스 –

+2

Google에서 검색하십시오. 지금까지 시도한 바가 있습니까 ?? –

+0

가능한 [안드로이드 액션 바 제목 센터 정렬 방법?] (http://stackoverflow.com/questions/21770428/how-to-make-android-action-bar-title-center-aligned) 가능한 복제본 – Pehlaj

답변

0

시도가 경쟁 텍스트를 추가하여 사용자 지정 제목을 만들 수 활동에이

<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"> 
<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Toolbar Title" 
    android:layout_gravity="center" 
    android:id="@+id/toolbar_title" /> 

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

전화 등의 도구 모음에서

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_top); 
setSupportActionBar(toolbar); 
getSupportActionBar().setDisplayShowTitleEnabled(false); 
TextView mTitle = (TextView) toolbar.findViewById(R.id.toolbar_title); 
mTitle.setText("any"); 
+0

다음 기본 앱 이름을 제거하는 방법 actionBar .. –

+0

getSupportActionBar(). setDisplayShowTitleEnabled (false); –

+0

당신은 완벽한 아래에 Hitesh 방법 대답을 사용할 수 있습니다 –

1

사용 도구 모음

<android.support.v7.widget.Toolbar 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/toolbar" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@drawable/img_header"> 


    <TextView 
     android:id="@+id/activity_title" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:gravity="center" 
     android:text="TITLE" 
     android:layout_gravity="center" 
     android:textColor="@android:color/white" 
     android:textSize="@dimen/dim_20" 
     android:typeface="serif" /> 
</android.support.v7.widget.Toolbar> 

세트 테마 NotitleBar

android:theme="@android:style/Theme.Translucent.NoTitleBar" 

또는

setSupportActionBar(findViewById(R.id.toolbar)); 
+0

다음 작업 모음에서 기본 앱 이름을 제거하는 방법 –

+0

내 대답을 편집했습니다. 다시 확인하십시오. –

1

이 시도 W :

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

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Android Toolbar" 
     android:textColor="@android:color/white" 
     android:textSize="18sp" 
     android:textStyle="bold" 
     android:layout_gravity="center" 
     android:id="@+id/toolbar_title" /> 

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

당신의 Activity에서 :

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
TextView mTitle = (TextView) toolbar.findViewById(R.id.toolbar_title); 

mTitle.setText("Your Title"); 

setSupportActionBar(toolbar); 
getSupportActionBar().setTitle(""); // Hide default app name 
관련 문제