0

Я хочу добавить TextView с изображением, как показано ниже изображения вместо имени приложения:Как добавить TextView в ActionBar вместо имени приложения с изображением

enter image description here

Я не хочу, чтобы удалить меню изображения. я просто хочу удалить имя приложения из панели действий и поместить этот вид текста, и на этом клике я хочу показать тост.

Как я могу это сделать?

ответ

0
ActionBar action = getSupportActionBar(); //get the actionbar 

action.setCustomView(R.layout.your_bar);//add the custom view 
action.setDisplayShowTitleEnabled(false); //hide the title 

после него, сделать макет с тем, что вы хотите как TextView, imageVie и т.д .. Надежды помогла и: D

1

Вы можете сделать свой собственный приложение бар XML. Включите панель приложений, где вы хотите показать, используя тег include. Не забудьте определить свою тему как NoActionBar в стилях.

<include 
     layout="@layout/tool_bar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 

Здесь панель инструментов XML

<?xml version="1.0" encoding="utf-8"?> 
    <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:background="@color/header_color" 
android:elevation="4dp" 
android:theme="@style/ThemeOverlay.AppCompat.Dark"> 


<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:paddingTop="5dp"> 
    <LinearLayout 

     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="0.2" 
     android:orientation="horizontal" 
     android:gravity="center"> 



    </LinearLayout> 

    <LinearLayout 

     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="3.5" 
     android:orientation="horizontal" 
     android:gravity="center_vertical"> 
     <TextView 
      android:id="@+id/txtTitle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 

      /> 



    </LinearLayout> 
    <LinearLayout 

     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:orientation="horizontal" 
     android:gravity="center"> 
     <ImageView 

      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/imageViewNotification" /> 


    </LinearLayout> 
    <LinearLayout 

     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:orientation="horizontal" 
     android:gravity="center"> 


     <ImageView 
      android:src="@drawable/tab_bar_profile" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/imageViewlogin" /> 
    </LinearLayout> 
</LinearLayout> 

Смежные вопросы