Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gsdukbh opened this issue Aug 12, 2024 · 3 comments

Comments

@gsdukbh
Copy link

gsdukbh commented Aug 12, 2024

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 gsdukbh added the bug label Aug 12, 2024
@gsdukbh
Copy link
Author

gsdukbh commented Aug 12, 2024

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 .

2024-08-12.22-49-48.mp4

@drchen
Copy link
Contributor

drchen commented Aug 16, 2024

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
Copy link
Author

gsdukbh commented Aug 19, 2024

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,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants