material-components / material-components-android

Modular and customizable Material Design UI components for Android
Apache License 2.0
16.25k stars 3.05k forks source link

[TextInputEditText +BottomSheetDialogFragment] Input method buttons cannot be displayed on Android12 #4256

Open gsdukbh opened 1 month ago

gsdukbh commented 1 month ago

Description: On Android 12 devices, the input method that pops up by clicking on the input box is gray and cannot be entered normally

Expected behavior: 如图所示,点击输入框后弹出的是灰色的一片内容, image

Source code:

# xml file 
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
  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">

    <com.google.android.material.bottomsheet.BottomSheetDragHandleView
      android:id="@+id/drag_handle"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"/>

    <androidx.constraintlayout.widget.ConstraintLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      >

      <Button
        android:id="@+id/close"
        style="?attr/materialIconButtonStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone"
        app:icon="@drawable/close"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

      <Button
        android:id="@+id/done"
        style="?attr/materialIconButtonStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:icon="@drawable/done"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

      <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:text="@string/add_input_title"
        android:textColor="@color/black"
        android:textSize="@dimen/mediumFont"
        app:layout_anchorGravity="top|center"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

      <com.google.android.material.divider.MaterialDivider
        android:id="@+id/cascade_divider"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/done"/>

      <com.google.android.material.progressindicator.LinearProgressIndicator
        android:id="@+id/loading"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="4dp"
        android:indeterminate="true"
        android:visibility="gone"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.498"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/cascade_divider"/>

      <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/ip"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:hint="@string/add_input_ip"
        app:endIconMode="clear_text"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/loading">
        <com.google.android.material.textfield.TextInputEditText
          android:id="@+id/ip_input"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:inputType="text"
          android:singleLine="true"
         />

      </com.google.android.material.textfield.TextInputLayout>

      <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/port"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="100dp"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:hint="@string/add_input_port"
        app:endIconMode="clear_text"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/ip"
        app:layout_constraintVertical_bias="0.0">
        <com.google.android.material.textfield.TextInputEditText
          android:id="@+id/port_input"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:inputType="number"
          android:singleLine="true" />

      </com.google.android.material.textfield.TextInputLayout>
    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
# in kotlin code
class AddressInputDialog : BottomSheetDialogFragment() {
  lateinit var binding: AddressInputDialogBinding
    private set

  var log: Logger
    private set
  private val model: CommonModel by viewModels<CommonModel> { ViewModelProvider.NewInstanceFactory() }

  init {
    log = LoggerFactory.getLogger(AddressInputDialog::class.java)
  }

  override fun onCreateView(
    inflater: LayoutInflater,
    container: ViewGroup?,
    savedInstanceState: Bundle?
  ): View? {
    binding = AddressInputDialogBinding.inflate(inflater, container, false)
    val ret: View = binding.root
    initView()
    return ret
  }

  fun initView() {
    val properties = Tools.loadConfig(context, "config.properties")
    if (properties.getProperty("ServerUrl") != null) {
      if (properties.getProperty("ip") != null) {

        binding.ipInput.setText(properties.getProperty("ip"))
        binding.portInput.setText(properties.getProperty("port"))
      } else {
        val regex = "http://([0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+):([0-9]+)/.*".toRegex()
        val matchResult = regex.find(properties.getProperty("ServerUrl")!!)
        if (matchResult != null) {
          val ip = matchResult.groupValues[1]
          val name = matchResult.groupValues[2]
          binding.ipInput.setText(ip)
          binding.portInput.setText(name)
        }

      }
    } else {
      binding.ipInput.setText("192.168.18.110")
      binding.portInput.setText("8082")
    }
    binding.done.setOnClickListener {
      val ip = binding.ipInput.text.toString()
      if (ip.isEmpty()) {
        binding.ipInput.error = getString(R.string.add_input_tip_1)
        return@setOnClickListener
      }
      val port = binding.portInput.text.toString()
      if (port.isEmpty()) {
        binding.portInput.error = getString(R.string.add_input_tip_2)
        return@setOnClickListener
      }
      val ipPattern =
        "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
      val domainPattern =
        "^(?=^.{1,253}$)(^(?:(?!\\d|-)[a-zA-Z0-9\\-]{1,63}(?<!-)\\.)+[a-zA-Z]{2,63}$)"
      if (!ip.matches(ipPattern.toRegex()) && !ip.matches(domainPattern.toRegex())) {
        binding.ipInput.error = getString(R.string.add_input_tip_3)
        return@setOnClickListener
      }
      log.info("ip:$ip port:$port")

      val url = "http://$ip:$port/MesWhsWebService"
      properties.setProperty("ServerUrl", url)
      properties.setProperty("ip", ip)
      properties.setProperty("port", port)
      Tools.saveConfig(context, "config.properties", properties)
      model.setOdin(true)
      dismiss()
    }
  }
}
 AddressInputDialog dialog = new AddressInputDialog();
      dialog.show(getSupportFragmentManager(), "AddressInputDialog");

Minimal sample app repro:

Android API version: Android API 31

Material Library version: Material Android Library android-material="1.12.0"

Device: android emulator Virtual Device android 12; and other android 12 Device ,eg: XIAOMI 10S

gsdukbh commented 1 month ago

This little video I recorded I've spent the last 5 hours troubleshooting this issue with no luck, I tried trying the same code on a new demo and it was fine. I don't know what issues are affecting this, please help .

https://github.com/user-attachments/assets/576b9a08-b3b5-49b7-8257-aae2d0b8b322

drchen commented 3 weeks ago

I can't reproduce the issue and it doesn't seem related to Material components.

Are you able to provide a minimal reproducible sample?

gsdukbh commented 3 weeks ago

I can't reproduce the issue and it doesn't seem related to Material components.

Are you able to provide a minimal reproducible sample?

simpleapp.zip

This is a simple example,