2017-10-21 29 views
0

이 코드와 toolbartogglebutton를 만들 tyring있어에서 ToggleButton을 들어갈 :제목 표시 줄 도구 모음

: enter image description here

<android.support.design.widget.AppBarLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:theme="@style/AppTheme.AppBarOverlay"> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="#acacac"> 
     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="#acacac" 
      app:layout_scrollFlags="scroll|enterAlways" 
      app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /> 
     <View 
      android:layout_width="match_parent" 
      android:layout_height="2dp" 
      android:layout_alignParentBottom="true" 
      android:background="#202020" /> 
     <ToggleButton 
      android:id="@+id/toggleButton" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:background="@drawable/check" 
      android:layout_margin="10dp" 
      android:focusable="false" 
      android:focusableInTouchMode="false" 
      android:textOn="" 
      android:textOff="" 
      android:layout_centerVertical="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" /> 
    </RelativeLayout> 
</android.support.design.widget.AppBarLayout> 

하지만 난 제목이 들어가거나 토글 버튼과 병합된다 제목을 설정하는 경우

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
setSupportActionBar(toolbar); 
if (getSupportActionBar() != null) { 
     getSupportActionBar().setDisplayShowHomeEnabled(true); 
    } 
settitle("stackoverflow"); 
+1

당신은 아래 왼쪽에서 오른쪽 또는 표시 할 위치를 원하는가? – Xenolion

+0

@Xenolion lwhen은 내가 문제가없는 작은 제목을 설정하지만 난 큰 제목을 설정할 때, 제목 텍스트는 그래서 당신은 괜찮이 https://i.imgur.com/pTTHtu0.png –

+1

같은 토글 버튼에 들어가 단어가 같이해야 할 것이다 경우 ** 스택 오버플로 즐은 ... (여기 토글 버튼) ** 세 개의 점을 볼 그것은 제목의 – Xenolion

답변

1

좋은 소식에 대한 Toolbar 이전 ActionBar이 도구 모음은 쉽게 사용자 정의 할 수 있습니다 것입니다 좋아하지. 레이아웃을 사용자 정의한 방법입니다. 먼저 수평 선형 레이아웃 Linear Layout을 툴바에보기로 추가했습니다. 그리고 나는 ToggleButton을 제거하고 지금 앱 제목이 될 것이다는 A TextViewLinearLayout에서 내부를 추가했습니다. 그리고 당신이 괜찮다면 당신이 당신의 새로운 Toolbar 첫째 삭제하십시오 (또는 숨기기)입니다 그래서 직접 ToogleButtonToolbar XML을 사용하여 제목을 설정할 수 있습니다 및 Toolbar가 어디에 위치에 다음 코드를 붙여 넣습니다.
을 당신이 당신의 텍스트는 점 (...)의 작은 당신이 그것을 볼 볼 수 이상으로 설정하려는 경우 : 그것은 지금까지 내 안드로이드 Studio에서 어떻게 보이는지

<android.support.v7.widget.Toolbar 
    android:id="@+id/toolbar" 
    android:layout_width="match_parent" 
    android:layout_height="?attr/actionBarSize" 
    android:background="?attr/colorPrimary"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <TextView 
      android:id="@+id/title" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="4dp" 
      android:layout_weight="1" 
      android:ellipsize="end" 
      android:lines="1" 
      android:text="title here or even @string/Something" 
      android:textColor="#ffffff" 
      android:textSize="20sp" /> 

     <ToggleButton 
      android:id="@+id/toggleButton" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:background="@drawable/check" 
      android:focusable="false" 
      android:focusableInTouchMode="false" 
      android:textOff="" 
      android:textOn="" /> 
    </LinearLayout> 
</android.support.v7.widget.Toolbar> 

이입니다 모든. 에서

Showing Longer words cropped

는 이제 하나의 코드 변화에 대해 이야기를 할 수 있습니다.

귀하의 Toolbar 제목은 TextView 당신이 더 이상 필요하지 않은 행의 값이됩니다.

toolbar.setTitle("stackoverflow"); 

당신은 당신의 TextView 직접 Javaxml에서 또는 코드를 사용할 수 있습니다. 일반 레이아웃처럼 TextSize도 증가 할 수 있습니다. 사용할 수있는 코드

TextView text_title=(TextView)findViewById(R.id.title); 
text_title.setText("stack Overflow"); 

해피 코딩!