工具栏ImageView和TextView内容不会更改

时间:2016-02-03 07:36:46

标签: 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>

请帮帮我。谢谢你提前

2 个答案:

答案 0 :(得分:1)

尝试使用此

    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);

答案 1 :(得分:0)

ImageView之后的第一集Toolbar

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

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

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