Search code examples
androidandroid-themeandroid-library

Style EditText in Android Library


I've created a Android library project with a custom prompt dialog. Therefore I used the normal EditText Widget. But it is not styled as it should on an Android 5 device...

As you can see in the screenshot it is only the basic old Android Theme (orange border).

Custom Dialog Screenshot

The EditText:

        <EditText
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/text_input"/>

Also tried it with style="@style/AppTheme" -> still same.

My styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
</style>

Also tried to add style attribute in my AndroidManifest.xml but I dont think that this will work in a library project (so still same orange border ...)

Next thing I tried... Created a custom EditText View:

public class MaterialEditText extends EditText {

public MaterialEditText(Context context) {
    super(context, null, R.style.Widget_AppCompat_EditText);
}

public MaterialEditText(Context context, AttributeSet attrs) {
    super(context, attrs, R.style.Widget_AppCompat_EditText);
}
}

-> no EditText is shown if I click on it I see the value of the EditText but I can't edit it.

How can I solve this?

Thank you very much!


Solution

  • As I can't fix it I use a drawable to simulate material style

    <?xml version="1.0" encoding="utf-8"?>
    

    <item android:id="@+id/border_bottom">
        <shape>
            <solid android:color="#2196f3" />
        </shape>
    </item>
    
    <!-- main color -->
    <item
            android:bottom="2dp"
            android:left="2dp"
            android:right="2dp">
        <shape>
            <solid android:color="#FAFBFB" />
        </shape>
    </item>
    
    <!-- draw another block to cut-off the left and right bars (holo -> 5dp) -->
    <item android:bottom="2dp">
        <shape>
            <solid android:color="#FAFBFB" />
        </shape>
    </item>