I created a custom EditText (actually, I just set a background drawable). The problem is that its text is always top-aligned, and I want it to be vertical-center-aligned. I've already tried to set its gravity to CENTER_VERTICAL, but it doesn't work. This is the drawable I created:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:gravity="center_vertical">
<solid android:color="#FFFFFF"/>
<stroke android:width="1dp" android:color="#88BA52" />
<corners
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"/>
</shape>
And here's how I create it:
searchEditText = new EditText(getContext());
searchEditText.setTextSize(12);
searchEditText.setSingleLine();
searchEditText.setGravity(Gravity.CENTER_VERTICAL);
searchEditText.setHint(R.string.search_hint);
searchEditText.setBackgroundDrawable(
getResources().getDrawable(R.drawable.search_field));
addView(searchEditText);
This might help