2017-02-07 1 views
0

툴바에 아이콘, 로고 및 텍스트 (다음)를 표시해야합니다. 다음은 오른쪽 정렬됩니다. 메뉴를 통해 텍스트 배치를 시도했습니다. 나는 툴바에 로고와 뒤로 버튼을 설정했다.툴바에 텍스트 만있는 메뉴가 표시되지 않습니다.

toolbar.setLogo(R.mipmap.logo); 
toolbar.setNavigationIcon(R.mipmap.back); 

은 또한, 나는

메뉴 팽창의 onCreateOptionsMenu에서 메뉴 다음과 팽창 한 :

<menu xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
> 
<item 
    android:id="@+id/action_next" 
    android:title="@string/next" 
    app:showAsAction="always" /> 

텍스트 메뉴가 전혀 표시되지 않습니다. 메뉴 항목에 아이콘을두면 표시됩니다. android.support.v7.widget.Toolbar를 사용했습니다.

편집 됨 :

나는 그것을 해결했다. 누군가 다른 사람이 그런 문제에 부딪 힐 경우.

스타일

<item name="android:actionMenuTextColor">@color/blue</item> 

를 추가하십시오. 메뉴 항목을 클릭 할 때 선택되지만 보이지 않았으므로 흰색 도구 모음에 흰색 텍스트 색상이 표시되었습니다. 메뉴 텍스트 색상을 설정하면 내 문제가 해결되었습니다. 액션 항목 :

+0

툴바 로고와 탐색 아이콘이 많은 공간을 차지한다고 생각합니다.'setSupportActionBar (toolbar)'를 추가 했습니까? –

+0

흰 툴바를 사용한다면 어둠을 테마로 사용하는 이유 ... 라이트 테마 메뉴를 사용하면 텍스트가 검은 색이됩니다. 가장 좋은 해결책은 –

+0

가벼운 테마를 사용했습니다. 하지만 colorPrimary를 흰색으로 지정해 어딘가에서 사용하고있었습니다. – seema

답변

0

Android DocumentationshowAsAction 것이다

에 대한 withText 옵션은 또한 (제목 안드로이드에 의해 정의) 제목 텍스트를 포함한다고 설명한다.

원하는 내용이므로 다음을 작성하십시오. ,

먼저 당신의 활동에 기본 제목을 제거 :

<item 
android:id="@+id/action_next" 
android:title="@string/next" 
app:showAsAction="always|withText" /> 
+0

감사합니다. 스타일에 메뉴 텍스트 색상을 추가하여 해결되었습니다. 지금 일하고있어. – seema

0

에게 당신은 이런 일을 할 수있는 그런

getSupportActionBar().setDisplayShowTitleEnabled(false); 

, 도구 모음 레이아웃은 다음과 같이 할 수있다 :

<LinearLayout 
    android:id="@+id/toolbar_layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <android.support.v7.widget.Toolbar 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="@color/material_blue" 
     android:elevation="5dp" 
     android:minHeight="?attr/actionBarSize" > 

     <TextView 
      android:id="@+id/toolbar_title" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="end" 
      android:gravity="end" 
      android:text="@string/app_name" 
      android:textColor="@android:color/white" /> 
    </android.support.v7.widget.Toolbar> 
</LinearLayout> 

그리고 귀하의 활동에서 클릭 이벤트를 처리하십시오 :

toolbarTop.findViewById(R.id.toolbar_title).setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     Log.d(TAG,"Clicked"); 
    } 
}); 
관련 문제