Android Studio: изменение текстового представления на пользовательской панели инструментов не работает - PullRequest
0 голосов
/ 21 апреля 2019

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

Правильно регистрирует diplay player.getCoin (), и установка TextViews на случайную строку, такую ​​как «Hello World», также не работает, что приводит меня к мысли, что проблема сложнее, чем я думал.

Пожалуйста, имейте в виду, что я удалил часть кода, которая не имеет отношения к вопросу, поэтому в файле activity_app_navigation.xml есть много ненужных вещей.

AppNavigation.java:

public class AppNavigation extends AppCompatActivity {

    public Player player;
    DrawerLayout drawerLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_app_navigation);

        drawerLayout = findViewById(R.id.drawer_layout);
        player = Player.getInstance();
        NavigationView navigationView = findViewById(R.id.nav_view);
        navigationView.setItemIconTintList(null);

        ((TextView) findViewById(R.id.coinText)).setText("New Text");
        ((TextView) findViewById(R.id.levelText)).setText("New Text");
        Log.i("PlayerCoin",String.valueOf(player.getCoin())); //logs correctly

    }

activity_app_navigation.xml:

<?xml version="1.0" encoding="utf-8"?>

<android.support.constraint.ConstraintLayout
    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"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/transparent"
    tools:context=".View.AppNavigation">


    <LinearLayout
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:fitsSystemWindows="true"
        android:orientation="horizontal"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:paddingLeft="8dp"
            android:paddingRight="115dp">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:fontFamily="@font/bellerose"
                android:text="@string/app_name"
                android:textColor="@color/colorPrimary"
                android:textSize="20dp" />

        </LinearLayout>


        <LinearLayout
            android:id="@+id/xpLayout"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:paddingRight="10dp"

            app:layout_constraintEnd_toStartOf="@id/coinsLayout">

            <TextView
                android:id="@+id/levelText"
                android:layout_width="50dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:fontFamily="@font/bellerose"
                android:text="Level"
                android:textColor="@color/white"
                android:textSize="20dp" />

        </LinearLayout>

        <!--COINS LAYOUT top nav-->
        <LinearLayout
            android:id="@+id/coinsLayout"
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            app:layout_constraintEnd_toEndOf="@id/toolbar"

            >


            <TextView
                android:id="@+id/coinText"
                android:layout_width="50dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:fontFamily="@font/bellerose"
                android:text="Coins"
                android:textAlignment="center"
                android:textColor="@color/white"
                android:textSize="20dp" />


            <Button
                android:id="@+id/coins"
                android:layout_width="33dp"
                android:layout_height="34dp"
                android:layout_gravity="center"
                android:background="@drawable/x_tracoin_01" />


        </LinearLayout>
    </LinearLayout>


    <RelativeLayout
        android:id="@+id/innerLayout"
        android:layout_width="match_parent"
        android:layout_height="496dp"
        android:layout_marginTop="56dp"
        android:layout_marginBottom="50dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


    <android.support.design.widget.BottomNavigationView
        android:id="@+id/navigationView"
        android:layout_width="425dp"
        android:layout_height="80dp"
        android:background="@color/transparent"
        app:itemIconSize="@android:dimen/app_icon_size"
        app:itemIconTint="@color/white"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/nav" />



</android.support.constraint.ConstraintLayout>
...