android - Toolbar ImageView 和 TextView 内容没有变化

标签 android android-toolbar

我试图更改我的工具栏图标和文本。我生成了 id,但我设置的文本未重新填充。我登录工具栏 TextView ,他显示正确的文本。
这里 Newmessage.java:-

     mInflater = (LayoutInflater)NewMessage.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = mInflater.inflate(R.layout.toolbar1, null);
         imageViewToolbar = (ImageView)convertView.findViewById(R.id.toolbar_imageview_new);
        textViewToolbar = (TextView)convertView.findViewById(R.id.messagename_std_text_view);

        Picasso.with(getApplicationContext()).load(path).into(imageViewToolbar);
        textViewToolbar.setText(title);

        toolbar = (Toolbar)findViewById(R.id.toolbar1);
        setSupportActionBar(toolbar);
        getSupportActionBar().setTitle("");
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);

这里是我的 toolbar.xml:-

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    local:popupTheme="@style/ThemeOverlay.AppCompat.Light">


    <RelativeLayout
        android:padding="5dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/toolbar_imageview_new"
            android:layout_width="50dp"
            android:layout_height="50dp"/>

        <TextView
            android:id="@+id/messagename_std_text_view"
            android:layout_toRightOf="@+id/toolbar_imageview_new"
            android:layout_toEndOf="@+id/toolbar_imageview_new"
            android:layout_centerVertical="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingBottom="5dp"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:textSize="20sp"
            android:text="rahul"
            android:textColor="#fff"/>


        <TextView
            android:id="@+id/toolbar_istyping"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/istyping"
            android:layout_below="@+id/messagename_std_text_view"
            android:layout_toRightOf="@+id/toolbar_imageview_new"
            android:layout_toEndOf="@+id/toolbar_imageview_new"
            android:textColor="#fff"
            android:paddingLeft="5dp"/>

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

请帮助我。提前致谢

最佳答案

尝试使用这个

    toolbar = (Toolbar)findViewById(R.id.toolbar1);
    imageViewToolbar = (ImageView)toolbar.findViewById(R.id.toolbar_imageview_new);
    textViewToolbar = (TextView)toolbar.findViewById(R.id.messagename_std_text_view);

    Picasso.with(getApplicationContext()).load(path).into(imageViewToolbar);
    textViewToolbar.setText(title);

    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle("");
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

关于android - Toolbar ImageView 和 TextView 内容没有变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35171056/

相关文章:

android - Places Api 在 android 中停止工作

android - 在模块 classes.jar com.google.android.gms :play-services-measurement-impl: 中发现重复的类 com.google.android.gms.internal.measurement.zzdu

android - 如何确定手机是否有缺口

android - Android 中使用 listview 隐藏工具栏

android - 使用键盘滚动屏幕时显示自定义工具栏

android - 在 AOSP Android 6.0 上更新 WebView

android - 为什么AndroidManifest.xml文件有多余的android :label attributes?

android - 如何在android中设置布局背景透明显示弹出窗口?

android - 使用导航组件处理工具栏后退按钮

android - 在 android 工具栏中正确实现 SearchView