2017-10-04 1 views
1

내 도구 모음 제목에 사용자 지정 텍스트가 필요합니다. 나는뒤로 단추가있는 도구 모음에서 사용자 정의 제목 사용

<android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:titleTextColor="?attr/TextColor"> 
     <TextView 
      android:textColor="?attr/TextColor" 
      android:id="@+id/toolbar_title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title" 
      android:layout_gravity="center" /> 

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

아래로 추가하고 자바에서 나는

toolbar = (Toolbar) findViewById(R.id.toolbar); 
     Typeface font=Typeface.createFromAsset(AuthorQuoteActivityTabs.this.getAssets(), constant.font); 
     TextView mTitle = (TextView) toolbar.findViewById(R.id.toolbar_title); 
     mTitle.setText("authorName"); 
     mTitle.setTypeface(font,Typeface.BOLD); 
     setSupportActionBar(toolbar); 
     if (getSupportActionBar() != null) { 
      getSupportActionBar().setDisplayHomeAsUpEnabled(true); 
     } 

아래의가 잘 작동하지만 도구 모음 사용자 정의 제목 텍스트뿐만 아니라 응용 프로그램 이름을 얻고있다처럼 코드를 작성했습니다. 내 사용자 정의 텍스트 만 원합니다. 기본 제목을 제거하고 툴바에서 사용자 정의 텍스트 만 사용하려면 어떻게합니까?

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
    toolbar.setTitle("Toolbar Title"); 
    setSupportActionBar(toolbar); 

그것을 희망 :

덕분에 별도의 텍스트 뷰에서 제목을 설정하는로

+0

툴바에 가운데 맞춤 텍스트를 사용하려는 경우 '툴바'내에 다른 'TextView'를 넣는 것만으로는 충분하지 않을 수 있습니다. 텍스트 위치는 툴바의 다른 항목 (뒤로 버튼, 메뉴 항목)에 따라 다릅니다. 이 질문을 볼 수 있습니다 : https://stackoverflow.com/questions/29443604/android-how-to-center-title-in-toolbar 이 도구는 가운데 도구 모음 – user2137020

답변

2

당신은이 코드를 사용하십시오

getSupportActionBar().setTitle(""); 
0

하여 "정상"제목을 제거해야 도와 드리겠습니다.

관련 문제