【发布时间】:2021-02-12 09:03:08
【问题描述】:
我已经定义了这个:
class ProfileFragment : Fragment(), View.OnClickListener {}
和点击:
override fun onClick(v: View?) {
when (v!!.id) {
binding.tvNavSetting -> {
avoidDoubleClicks(binding.tvNavSetting)
val intent = Intent(requireContext(), SettingsActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
}
}
}
这是我的抽屉和 Profile Fragment.xml 内部:
<com.google.android.material.navigation.NavigationView
app:elevation="10dp"
android:id="@+id/nav_view"
android:paddingBottom="100dp"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="@color/white"
android:fitsSystemWindows="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.appcompat.widget.SearchView
android:layout_width="match_parent"
android:layout_height="40dp"
android:id="@+id/seach_view"
android:background="@drawable/bg_search"
android:layout_marginHorizontal="10dp"
android:layout_marginVertical="10dp"/>
// this is what i try to call:////
<TextView
android:id="@+id/tv_nav_setting"
android:text="awdadw"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/black" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="40dp"
android:background="@drawable/drawer_bg" />
</LinearLayout>
<Button
android:id="@+id/btn_keluar_profile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Keluar"
android:layout_margin="10dp"
android:textColor="@color/white"
android:background="@drawable/bg_btn_login"
android:layout_gravity="bottom"/>
</com.google.android.material.navigation.NavigationView>
我在 Fragment 内的抽屉导航中有文本视图。我想在该抽屉导航中处理点击,但文本视图无法通过 viewBinding 调用。请看下面的错误图片。。
【问题讨论】:
标签: android kotlin android-viewbinding