我试图在我的应用程序的家庭活动中添加工具栏。我有以下问题。error: incompatible types: android.widget.Toolbar cannot be converted to androidx.appcompat.widget.Toolbar.
。我的“工具栏”用红色下划线。
知道会是什么吗?我只发现这可能是导入问题,但我已经尝试更改它,但没有成功。
谢谢。
这是我的XML代码:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:minHeight="?actionBarTheme"
android:theme="?actionBarTheme"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navigationIcon="@drawable/menubuttonofthreelines_79781">
</androidx.appcompat.widget.Toolbar>
</ScrollView>
这是我的HomeActivity代码:
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBarDrawerToggle toogle = new ActionBarDrawerToggle(this,drawerLayout,toolbar,
R.string.navigation_drawer_open,R.string.navigation_drawer_close);
drawerLayout.addDrawerListener(toogle);
toogle.syncState();
在Java活动文件中,从android.widget
包中删除工具栏
import android.widget.Toolbar;
并从androidx.appcompat.widget
包中添加androidx工具栏
import androidx.appcompat.widget.Toolbar;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句