I am using an EditText
inside a Toolbar
, no matter what I do, cursor and underline doesn't appear
xml code
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
app:collapseIcon="@drawable/ic_arrow_up_24dp"
app:titleTextColor="@color/white"
android:layout_alignParentTop="true"
android:animateLayoutChanges="true"
android:visibility="gone"
android:alpha="0.0"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:cursorVisible="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_height="wrap_content"
android:hint="Search..."
android:textCursorDrawable="@color/white"
android:textColor="@color/md_white_1000"
android:layout_marginRight="120dp"
/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
kotlin code
editText?.visibility = View.VISIBLE
editText?.requestFocus()
editText?.isCursorVisible = true
editText.setRawInputType(InputType.TYPE_CLASS_TEXT);
editText.setTextIsSelectable(true);
Where am I going wrong, can anyone help?
This is because by default the underline and cursor of EditText is of colorAccent
. So, if you want to change their color to suppose white, then you should define a style in styles.xml
like this:
<style name="editText" parent="AppTheme">
<item name="colorAccent">@color/white</item>
</style>
And then apply this style as theme to edittext like this:
<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:cursorVisible="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_height="wrap_content"
android:hint="Search..."
android:textCursorDrawable="@color/white"
android:textColor="@color/md_white_1000"
android:theme="@style/editText"
android:layout_marginRight="120dp"
/>