我有一个AppNavigation类,这是一个自定义的linearview工具栏,其他活动继承自该工具栏,从而获得顶部工具栏。在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>