I have a Plain Text field on a screen that is a search bar. I want to make it so that the hint for the search bar is a PNG. I have a few issues:
- The PNG is way too large.
- The PNG doesn't disappear when I start typing.
- The letters appear all the way to the right of the edit text.
When the user touches the search bar to pull up the keyboard, the PNG should disappear. Anything they type should show up. When they click away, the text should be wiped and the PNG should reappear again.
Here is a screenshot:
And here is the code:
package com.example.testapp
import android.content.SharedPreferences
import android.os.Bundle
import android.text.Editable
import android.view.View
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_home.*
class HomeActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_home)
supportActionBar?.hide()
val searchForEditText: EditText = findViewById(R.id.search_for_edittext)
searchForEditText.setCompoundDrawablesWithIntrinsicBounds(R.drawable.search_for_grey, 0, 0, 0)
// afterTextChanged(searchForEditText.text)
OnFocusChangeListener(searchForEditText, searchForEditText.didTouchFocusSelect())
}
private fun OnFocusChangeListener(v: View, state: Boolean){
if (state && v.toString().isNotEmpty()) {
search_for_edittext.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null)
} else {
search_for_edittext.setCompoundDrawablesWithIntrinsicBounds(R.drawable.search_for_grey, 0, 0, 0)
}
}
}
Side question - is this how main stream apps do hints? I know there's a built-in hint feature for Edit Texts, but do bigger companies use PNGs for hints so that their apps look nicer?