我有一个CustomEditText扩展EmojiEditText,它扩展了AppCompatEditText并派生了https://github.com/vanniktech/Emoji库。
我曾经为CustomEditText使用ComposeEditText样式。但是如果我添加这种风格,应用程序就会崩溃。请帮帮我。
我的编辑文字样式:
<style name="ComposeEditText" parent="@style/Widget.AppCompat.EditText">
<item name="android:padding">2dp</item>
<item name="android:background">@null</item>
<item name="android:maxLines">4</item>
<item name="android:maxLength">2000</item>
<item name="android:capitalize">sentences</item>
<item name="android:autoText">true</item>
<item name="android:gravity">center_vertical</item>
<item name="android:imeOptions">flagNoEnterAction</item>
<item name="android:inputType">textAutoCorrect|textCapSentences|textMultiLine</item>
</style>
我在xml中的edittext:
<com.android.android.util.view.CustomEditText
android:id="@+id/editText"
style="@style/ComposeEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
app:emojiSize="@dimen/emojiSize" />
代码:
public class CustomEditText extends EmojiEditText {
public CustomEditText(Context context) {
super(context);
}
public CustomEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
@SuppressLint("DrawAllocation")
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
}
}
错误日志:
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.android.android/com.android.android.conversation.a.PRofile}:
android.view.InflateException: Binary XML file line #0:
Binary XML file line #0: Error inflating class com.android.android.util.view.CustomEditText
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2927)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class com.android.android.util.view.CustomEditText
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class com.android.android.util.view.CustomEditText
Caused by: java.lang.reflect.InvocationTargetException
答案 0 :(得分:1)
看到您的CustomEditText
EmojiEditText
,请尝试将您的样式的parent
设置为EmojiEditText的样式。我认为问题是你的风格是继承错误的风格
答案 1 :(得分:0)
我只是删除&#34; @style /&#34;它解决了。谢谢你的帮助
而不是
<style name="ComposeEditText" parent="@style/Widget.AppCompat.EditText">
使用
<style name="ComposeEditText" parent="Widget.AppCompat.EditText">