Android 库中的 EditText 样式

Style EditText in Android Library

我创建了一个带有自定义提示对话框的 Android 库项目。 因此我使用了普通的 EditText Widget。 但是它的样式在 Android 5 设备上不应该...

如您在屏幕截图中所见,它只是基本的旧 Android 主题(橙色边框)。

Custom Dialog Screenshot

编辑文本:

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

也尝试了 style="@style/AppTheme" -> 还是一样。

我的styles.xml

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

还尝试在我的 AndroidManifest.xml 中添加样式属性,但我认为这不会在库项目中起作用(所以仍然是相同的橙色边框...)

接下来我尝试了... 创建了自定义 EditText 视图:

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);
}
}

-> 如果我单击它,则不会显示任何 EditText 我看到了 EditText 的值,但我无法编辑它。

我该如何解决这个问题?

非常感谢!

基本上一个解决方案是更改清单中的样式属性。

android:theme="@style/AppTheme"

出于某种原因,您必须将样式更改为默认样式才能使另一个样式库正常工作。

只需在该属性的引号之间按 "Alt + Space" 即可尝试不同的样式。

因为我无法修复它,所以我使用 drawable 来模拟 material 样式

<?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>