I am working with Platform View in Flutter and I want to return a VIEW in my getView()
constructor.
I have an .xml
file with the View group that I want to return to in this. My question is how to return this since my constructor returns a VIEW.
That is the sample code:
internal class SBNativeView(context: Context, id: Int, creationParams: Map<String?, Any?>?) : PlatformView, AppCompatActivity() {
private val textView: TextView
override fun getView(): View {
return textView
}
override fun dispose() {}
init {
textView = TextView(context)
textView.textSize = 72f
textView.setBackgroundColor(Color.rgb(255, 255, 255))
textView.text = "Rendered on a native Android view (id: $id)"
}
}
I need return this view
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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:id="@+id/loginConstraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textlayout_login_user_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="48dp"
android:layout_marginEnd="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edittext_login_user_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="UserID"
android:imeOptions="actionDone"
android:inputType="textVisiblePassword"/>
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textlayout_login_nickname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="16dp"
app:layout_constraintTop_toBottomOf="@+id/textlayout_login_user_id">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edittext_login_nickname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Nickname"
android:imeOptions="actionDone"
android:inputType="textVisiblePassword"/>
</com.google.android.material.textfield.TextInputLayout>
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/button_login_connect"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="match_parent"
android:layout_height="44dp"
android:layout_marginStart="16dp"
android:layout_marginTop="44dp"
android:layout_marginEnd="16dp"
android:background="#774df2"
android:stateListAnimator="@null"
android:text="Connect"
app:layout_constraintTop_toBottomOf="@+id/textlayout_login_nickname"/>
</androidx.constraintlayout.widget.ConstraintLayout>
How Can I return this view in getView()?
question from:
https://stackoverflow.com/questions/65926241/how-can-access-a-view-in-android 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…