我有一个主布局,我使用标签来包含另一个布局,现在,在包含该布局的内部,我有一个按钮想要单击主布局,但我不能。
MainLayout
<LinearLayout
...
<include
android:id="@+id/update_container"
layout="@layout/update_container"
android:visibility="gone" />
...
</LinearLayout>
第二个包含布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_gravity="center"
android:orientation="vertical"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_update"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="8dp"
android:textSize="18sp"
android:textStyle="bold"
android:padding="16dp"
android:fontFamily="sans-serif"
android:text="There is an update available"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_update"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Descargar"
android:layout_marginTop="8dp"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
app:strokeColor="@color/colorPrimary"/>
</LinearLayout>
现在我尝试从打开第一个布局的主片段访问btn_update
update_container.visibility = View.VISIBLE
update_container.btn_actualizar.setOnClickListener {
openAppInGooglePlay()
requireActivity().finish()
}
我在这里使用Kotlin合成材料,但我认为没有达到按钮,单击时什么也没发生
任何提示?
谢谢
您仍然应该使用btn_update并导入必要的需求,例如findViewById,合成或视图绑定,无论使用哪种。