I encountered a strange problem. My Android app would crash whenever I add an EditText
in an Activity
. To test, I open a new clean project, and the new project will crash if there is an EditText
as well. Therefore, I think the problem is caused from Android Studio or other environment setting.
Following is the activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
android:id="@+id/activity_main"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="yichun.myapplication.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:id="@+id/textView"
app:layout_constraintLeft_toLeftOf="@+id/activity_main"
app:layout_constraintTop_toTopOf="@+id/activity_main"
app:layout_constraintRight_toRightOf="@+id/activity_main"
app:layout_constraintBottom_toBottomOf="@+id/activity_main"/>
<EditText
android:layout_width="218dp"
android:layout_height="45dp"
android:inputType="textPersonName"
android:text="Name"
android:ems="10"
tools:layout_editor_absoluteX="90dp"
android:id="@+id/editText"
app:layout_constraintBottom_toTopOf="@+id/textView" android:layout_marginBottom="40dp"/>
</android.support.constraint.ConstraintLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
Error message
E/AndroidRuntime: FATAL EXCEPTION: main
Process: yichun.myapplication, PID: 3239
java.lang.RuntimeException: Unable to start activity ComponentInfo{yichun.myapplication/yichun.myapplication.MainActivity}: android.view.InflateException: Binary XML file line #20: Error inflating class EditText
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class EditText
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at yichun.myapplication.MainActivity.onCreate(MainActivity.java:11)
at android.app.Activity.performCreate(Activity.java:5937)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-v21/abc_edit_text_material.xml from drawable resource ID #0x7f020015
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2428)
at android.content.res.Resources.loadDrawable(Resources.java:2330)
at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
at android.view.View.<init>(View.java:3730)
at android.widget.TextView.<init>(TextView.java:634)
at android.widget.EditText.<init>(EditText.java:65)
at android.widget.EditText.<init>(EditText.java:61)
at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:60)
at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:56)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:112)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:980)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1039)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at yichun.myapplication.MainActivity.onCreate(MainActivity.java:11)
at android.app.Activity.performCreate(Activity.java:5937)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #24: <nine-patch> requires a valid 9-patch source image
at android.graphics.drawable.NinePatchDrawable.updateStateFromTypedArray(NinePatchDrawable.java:445)
at android.graphics.drawable.NinePatchDrawable.inflate(NinePatchDrawable.java:401)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1095)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:185)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1095)
at android.graphics.drawable.InsetDrawable.inflate(InsetDrawable.java:104)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1095)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1017)
at android.content.res.Resources.loadDrawableForCookie(Resources.java:2418)
at android.content.res.Resources.loadDrawable(Resources.java:2330)
at android.content.res.TypedArray.getDrawable(TypedArray.java:749)
at android.view.View.<init>(View.java:3730)
at android.widget.TextView.<init>(TextView.java:634)
at android.widget.EditText.<init>(EditText.java:65)
at android.widget.EditText.<init>(EditText.java:61)
at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:60)
at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:56)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:112)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:980)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1039)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:725)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at yichun.myapplication.MainActivity.onCreate(MainActivity.java:11)
at android.app.Activity.performCreate(Activity.java:5937)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
at android.app.ActivityThread.access$800(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
Good afternoon, I’m trying to solve a problem but I can not. I have two smartphones, a Nexus 5(Android 6.0) and one ZenFone 2(Android 5.0). The error only persisted only in ZenFone.
XML:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/TextLabel">
<EditText
android:id="@+id/et_login_pass"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/LoginPlaceholderPassword"
android:inputType="textPassword"/>
</android.support.design.widget.TextInputLayout>
android.view.InflateException: Binary XML file line #25: Error
inflating class EditText
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
What do I do?
asked Oct 29, 2015 at 15:57
vianaviana
4954 gold badges18 silver badges42 bronze badges
2
Can you change your layout_width
to match_parent
and check if your definitely compiling the two dependencies you need in your build.gradle file please.
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:design:23.1.0'
answered Oct 29, 2015 at 16:31
vguzzivguzzi
2,4002 gold badges15 silver badges19 bronze badges
1
I had the same issue here with ZenFone 2(Android 5.0).
Update your Android Support to:
compile 'com.android.support:design:25.3.0'
Remove:
android:theme="@style/TextLabel"
PS: Please replace fill_parent to match_parent =)
answered Apr 27, 2017 at 1:35
Just create a sub class that extends EditText.
For Example:
public class Text extends EditText {
public Text(Context context, AttributeSet attrs) {
super(context, attrs);
}
}
Then use this class in xml file instaed of EditText
<com.example.edittextproblem.Text
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="haha"/>
and your problem will be solved
answered Jul 3, 2016 at 5:49
Same issue but with Buttons.
android.view.InflateException: Binary XML file line #0: Error inflating class Button
Device: LG G3
Operating System: 4.4.2
`
Caused by android.content.res.Resources$NotFoundException
| android.content.res.Resources.loadDrawable (Resources.java:2136)
| android.support.v7.app.AppCompatDelegateImplV9.onCreateView (Unknown Source)
| uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$WrapperFactory2.onCreateView (Unknown Source)
| android.view.LayoutInflater$FactoryMerger.onCreateView (LayoutInflater.java:172)
| android.view.LayoutInflater.inflate (LayoutInflater.java:492)
| uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate (Unknown Source)
| android.view.LayoutInflater.inflate (LayoutInflater.java:397)
| com.buildone.delivery.features.profile.DriverProfileFragment.onCreateView (Unknown Source)
| android.support.v4.app.Fragment.performCreateView (Unknown Source)
| dalvik.system.NativeStart.main (NativeStart.java)
Caused by org.xmlpull.v1.XmlPullParserException
| android.graphics.drawable.Drawable.createFromXmlInner (Drawable.java:933)
| android.support.v7.app.AppCompatDelegateImplV9.onCreateView (Unknown Source)
| uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$WrapperFactory2.onCreateView (Unknown Source)
| android.view.LayoutInflater$FactoryMerger.onCreateView (LayoutInflater.java:172)
| android.view.LayoutInflater.inflate (LayoutInflater.java:492)
| uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate (Unknown Source)
| android.view.LayoutInflater.inflate (LayoutInflater.java:397)
| com.buildone.delivery.features.profile.DriverProfileFragment.onCreateView (Unknown Source)
| android.support.v4.app.Fragment.performCreateView (Unknown Source)
| dalvik.system.NativeStart.main (NativeStart.java)
EDIT:
My problem was using vector drawables in android buttons. Not related to calligraphy.
User389297 posted
Hello. I’m really at my wits end with this one. I’ve battled this Inflater Error for a while now, got it to go away by installing NuGet package v7 AppCompat but it is back now when I add an EditText to my second fragment. The first fragment has EditText and multiple other controls, and the whole thing works fine with TextViews in the second fragment, but the moment I add an EditText it all breaks down at deployment.
Error message
Unhandled Exception:
Android.Views.InflateException: Binary XML file line #1 in com.brandycakes.just_the_tip:layout/activity_main: Binary XML file line #1 in com.brandycakes.just_the_tip:layout/activity_main: Error inflating class android.support.design.widget.BottomNavigationView occurred
Activity_main:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="56dp" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:attr/windowBackground"
android:layout_alignParentBottom="true"
app:menu="@menu/navigation" />
</RelativeLayout>
Fragment 1 (Tip Calc):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:text="Just The Tip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:gravity="center"
android:textStyle="bold"
android:textSize="20dp"
android:textColor="@color/colorTextPrimary"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:id="@+id/inputBill"
android:backgroundTint="#d6d7d7"
android:focusedByDefault="true" />
<TextView
android:text="Tip Percentage: "
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_margin="25px"
android:id="@+id/tipPercentage"
android:textColor="@color/colorTextPrimary"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:max="25"
android:progress="15"
android:id="@+id/seekBarTip" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="CALCULATE"
android:layout_margin="80px"
android:id="@+id/calculateButton"
android:textColor="@color/colorTextPrimary"/>
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:textSize="100px"
android:textStyle="bold"
android:gravity="center"
android:id="@+id/roundedTip" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout2">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:textSize="100px"
android:textStyle="bold"
android:gravity="center"
android:id="@+id/roundedTotal" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout3">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:textSize="80px"
android:gravity="center"
android:id="@+id/roundedPercentage" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/linearLayout4">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:textSize="80px"
android:gravity="center"
android:id="@+id/outputTip" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="80px"
android:id="@+id/linearLayout5">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:textSize="80px"
android:gravity="center"
android:id="@+id/outputTotal" />
</LinearLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:backgroundTint="@color/colorFAB"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right|end"
android:layout_marginBottom="500dp"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@drawable/refresh" />
</LinearLayout>
Fragment 2(Bill Split):
<TextView
android:text="Split The Bill"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:gravity="center"
android:textStyle="bold"
android:textSize="20dp"
android:textColor="@color/colorTextPrimary"/>
<TextView
android:text="Bill Total"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/colorTextPrimary"
android:textStyle="bold" />
<EditText
android:id="@+id/txtBillTotal"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Again, everything is totally fine before I add that last EditText. I can add any other code you guys might want to see, just say the word. Hopefully someone can save me here because I have no idea what’s going on. Thanks so much in advance!
Issue
I am getting tired of fixing this problem. Always show me this error
Binary XML file line #11: Error inflating class EditText.
I don’t understand how to fix this problem. Already tried many StackOverflow answers but failed.
Using Gradle 7.1.0 version. Device Pixel 4 API 27.
XML file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/PrimaryLight"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="@+id/etID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="15dp"
android:layout_marginRight="15dp"
android:ems="10"
android:gravity="center_horizontal"
android:hint="@string/hint_id"
android:inputType="number"
android:minHeight="48dp"
android:textColorHint="@color/material_dynamic_neutral10"
android:importantForAutofill="no" />
</LinearLayout>
Error message:
2022-02-02 17:05:04.720 9809-9809/com.example.magicidapplication E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.magicidapplication, PID: 9809
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.magicidapplication/com.example.magicidapplication.MainActivity}: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class EditText
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: android.view.InflateException: Binary XML file line #11: Binary XML file line #11: Error inflating class EditText
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class EditText
Caused by: java.lang.UnsupportedOperationException: Can't convert to ComplexColor: type=0x1
Solution
As pointed out by the stacktrace Caused by: java.lang.UnsupportedOperationException: Can't convert to ComplexColor: type=0x1
there is some issue in the @color/material_dynamic_neutral10
color change it to something else or remove it
Answered By – Taranmeet Singh
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0
#android #android-layout #gradle #android-edittext #inflate-exception
#Android #android-макет #gradle #android-edittext #раздувать -исключение
Вопрос:
Я пытаюсь создать страницу входа в систему, используя шаблон Android по умолчанию. Ниже приведен мой код для макета:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.login.app.logintest.LoginActivity">
<!-- Login progress -->
<ProgressBar
android:id="@ id/login_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:visibility="gone" />
<ScrollView
android:id="@ id/login_form"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@ id/email_login_form"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@ id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_email"
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@ id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/prompt_password"
android:imeActionId="@ id/login"
android:imeActionLabel="@string/action_sign_in_short"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<Button
android:id="@ id/email_sign_in_button"
style="?android:textAppearanceSmall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/action_sign_in"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
</LinearLayout>
Но я получаю исключение инфляции при редактировании текста электронной почты.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.login.app.logintest/com.login.app.logintest.LoginActivity}: android.view.InflateException: Binary XML file line #37: Error inflating class EditText
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2790)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2855)
at android.app.ActivityThread.access$900(ActivityThread.java:181)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6117)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: android.view.InflateException: Binary XML file line #37: Error inflating class EditText
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:770)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
Пожалуйста, предложите решение.
К вашему сведению, я использую gradle версии 2.1 в Android Studio.
Спасибо, Рахул
Комментарии:
1. какую версию библиотеки дизайна вы используете??
2. зачем вам нужен android:imeActionLabel в xml? вместо этого используйте setImeActionLabel в коде EditText.setImeActionLabel(getString(R.string.xxx), EditorInfo. IME_ACTION_GO); Аналогично вы намереваетесь выполнить определенное в этом developer.android.com/guide/topics/ui/controls/text.html ?
Ответ №1:
Вместо того, чтобы использовать android:imeActionLabel в xml-файле, попробуйте переместить его в код Java следующим образом
editText.setImeActionLabel(getString(R.string.your_string), EditorInfo.IME_ACTION_GO);
Если вы не собираетесь выполнять предопределенные действия с помощью опции IME, тогда лучше избегать android:imeActionId
, android:imeActionLabel
и android:imeOptions
. Для получения дополнительной информации проверьте эту ссылку
Ответ №2:
Попробуйте использовать android.support.v7.widget.AppCompatEditText
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.AppCompatEditText
............ />
</android.support.design.widget.TextInputLayout>
Убедитесь, что вы используете библиотеку дизайна выше 22.2.1, как показано ниже:
dependencies {
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
}
I am trying to inflate a layout into a fragment and have a very frustrating error
WHY ONLY EDITTEXT causing error
My fragment layout Code usb_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Begin"
android:id="@+id/buttonStart"
android:layout_below="@+id/editText"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:onClick="onClickStart"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send"
android:id="@+id/buttonSend"
android:onClick="onClickSend"
android:layout_below="@+id/editText"
android:layout_toRightOf="@+id/buttonStart"
android:layout_toEndOf="@+id/buttonStart" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:layout_below="@+id/buttonSend"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="@+id/editText"
android:layout_alignEnd="@+id/editText"
android:layout_alignParentBottom="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stop"
android:id="@+id/buttonStop"
android:layout_below="@+id/editText"
android:layout_toRightOf="@+id/buttonSend"
android:layout_toEndOf="@+id/buttonSend"
android:onClick="onClickStop"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear"
android:id="@+id/buttonClear"
android:layout_below="@+id/editText"
android:layout_toRightOf="@+id/buttonStop"
android:layout_toEndOf="@+id/buttonStop"
android:onClick="onClickClear"/>
</LinearLayout>
My fragment code Usb.java
package com.example.rajat.blueusb
import android.app.Fragment;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbDeviceConnection;
import android.hardware.usb.UsbManager;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.felhr.usbserial.UsbSerialDevice;
import com.felhr.usbserial.UsbSerialInterface;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Map;
public class Usb extends Fragment {
public Usb(){}
public final String ACTION_USB_PERMISSION = "com.example.rajat.blueusb.USB_PERMISSION";
Button startButton, sendButton, clearButton, stopButton;
TextView textView;
EditText editText;
UsbManager usbManager;
UsbDevice device;
UsbSerialDevice serialPort;
UsbDeviceConnection connection;
UsbSerialInterface.UsbReadCallback mCallback = new UsbSerialInterface.UsbReadCallback() { //Defining a Callback which triggers whenever data is read.
@Override
public void onReceivedData(byte[] arg0) {
String data = null;
try {
data = new String(arg0, "UTF-8");
data.concat("/n");
tvAppend(textView, data);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
};
private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() { //Broadcast Receiver to automatically start and stop the Serial connection.
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(ACTION_USB_PERMISSION)) {
boolean granted = intent.getExtras().getBoolean(UsbManager.EXTRA_PERMISSION_GRANTED);
if (granted) {
connection = usbManager.openDevice(device);
serialPort = UsbSerialDevice.createUsbSerialDevice(device, connection);
if (serialPort != null) {
if (serialPort.open()) { //Set Serial Connection Parameters.
setUiEnabled(true);
serialPort.setBaudRate(9600);
serialPort.setDataBits(UsbSerialInterface.DATA_BITS_8);
serialPort.setStopBits(UsbSerialInterface.STOP_BITS_1);
serialPort.setParity(UsbSerialInterface.PARITY_NONE);
serialPort.setFlowControl(UsbSerialInterface.FLOW_CONTROL_OFF);
serialPort.read(mCallback);
tvAppend(textView,"Serial Connection Opened!n");
} else {
Log.d("SERIAL", "PORT NOT OPEN");
}
} else {
Log.d("SERIAL", "PORT IS NULL");
}
} else {
Log.d("SERIAL", "PERM NOT GRANTED");
}
} else if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_ATTACHED)) {
onClickStart(startButton);
} else if (intent.getAction().equals(UsbManager.ACTION_USB_DEVICE_DETACHED)) {
onClickStop(stopButton);
}
}
;
};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.usb_view, container, false);
usbManager = (UsbManager) getActivity(). getSystemService(Context.USB_SERVICE);
startButton = (Button)getView(). findViewById(R.id.buttonStart);
sendButton = (Button)getView(). findViewById(R.id.buttonSend);
clearButton = (Button)getView(). findViewById(R.id.buttonClear);
stopButton = (Button)getView(). findViewById(R.id.buttonStop);
editText = (EditText)getView().findViewById(R.id.editText);
textView = (TextView)getView().findViewById(R.id.textView);
setUiEnabled(false);
IntentFilter filter = new IntentFilter();
filter.addAction(ACTION_USB_PERMISSION);
filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
getActivity().registerReceiver(broadcastReceiver, filter);
return rootView;
}
public void setUiEnabled(boolean bool) {
startButton.setEnabled(!bool);
sendButton.setEnabled(bool);
stopButton.setEnabled(bool);
textView.setEnabled(bool);
}
public void onClickStart(View view) {
HashMap<String, UsbDevice> usbDevices = usbManager.getDeviceList();
if (!usbDevices.isEmpty()) {
boolean keep = true;
for (Map.Entry<String, UsbDevice> entry : usbDevices.entrySet()) {
device = entry.getValue();
int deviceVID = device.getVendorId();
if (deviceVID ==1659)//Arduino Vendor ID
{
PendingIntent pi = PendingIntent.getBroadcast(getActivity().getApplicationContext(), 0, new Intent(ACTION_USB_PERMISSION), 0);
usbManager.requestPermission(device, pi);
keep = false;
break;
} else {
connection = null;
device = null;
}
if (!keep)
break;
}
}
}
public void onClickSend(View view) {
String string = editText.getText().toString();
serialPort.write(string.getBytes());
tvAppend(textView, "nData Sent : " + string + "n");
}
public void onClickStop(View view) {
setUiEnabled(false);
serialPort.close();
tvAppend(textView,"nSerial Connection Closed! n");
}
public void onClickClear(View view) {
textView.setText(" ");
}
private void tvAppend(TextView tv, CharSequence text) {
final TextView ftv = tv;
final CharSequence ftext = text;
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
ftv.append(ftext);
}
});
}
}
My MainActivity.java code
package com.example.rajat.blueusb;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.app.Fragment;
import android.app.FragmentManager;
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
Fragment fragment=null;
int id = item.getItemId();
if (id == R.id.nav_usb) {
fragment = new Usb();
} else if (id == R.id.nav_blue) {
fragment = new Bluetooth();
}
if (fragment != null) {
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.content_main, fragment).commit();
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
LOGCAT:
android.view.InflateException: Binary XML file line #6: Error inflating class EditText
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:763)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
at com.example.rajat.blueusb.Usb.onCreateView(Usb.java:109)
at android.app.Fragment.performCreateView(Fragment.java:2069)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:899)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1072)
You can’t align your view to Left and Right at the same time.
If you wan’t to align your EditText
to left:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
Я использую механизм пользовательского интерфейса TextInputLayout на моей странице входа в приложение, все работает отлично, за исключением устройства, которое запускает версию 4.4.2 для Android на этих устройствах. У меня есть исключение.
Это мой макет:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include android:id="@+id/loginInfiLogoRL"
layout="@layout/login_infi_logo_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="-3dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"/>
<!--EMAIL-->
<android.support.design.widget.TextInputLayout
android:id="@+id/email_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/loginInfiLogoRL"
android:theme="@style/TextLabel">
<EditText
android:id="@+id/etUserName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/login_screen_email_hint"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:maxLines="1"
android:nextFocusDown="@+id/etPassword"
android:singleLine="true"
android:textColor="@android:color/white"
android:textColorHighlight="@color/Orange"
android:textColorHint="@android:color/white" />
</android.support.design.widget.TextInputLayout>
<RelativeLayout
android:id="@+id/rlPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:layout_below="@id/email_wrapper">
<!--PASSWORD-->
<android.support.design.widget.TextInputLayout
android:id="@+id/password_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/TextLabel">
<EditText
android:id="@+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/login_screen_password_hint"
android:imeOptions="actionNext"
android:inputType="textPassword"
android:maxLines="1"
android:nextFocusDown="@+id/bSignIn"
android:shadowColor="@color/Orange"
android:singleLine="true"
android:textColor="@android:color/white"
android:textColorHint="@android:color/white" />
</android.support.design.widget.TextInputLayout>
<!--FORGOT-->
<TextView
android:id="@+id/tvForgotPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:paddingBottom="14dp"
android:paddingRight="10dp"
android:text="@string/login_screen_forgot_password_text"
android:textColor="@color/Orange"
android:textSize="16sp" />
</RelativeLayout>
<TextView
android:id="@+id/tvRememberMe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="invisible" />
<!--Buttons Login and SignUp-->
<LinearLayout
android:id="@+id/llSignUp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:gravity="center_vertical"
android:layout_below="@+id/rlPassword">
<!--Sign up Button-->
<TextView
android:id="@+id/bSignUp"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginRight="16dp"
android:layout_weight="1"
android:textSize="18sp"
android:gravity="center"
android:imeOptions="actionGo"
android:text="@string/login_screen_sign_up_button_text"
android:textColor="@color/Orange" />
<!--Login Button-->
<Button
android:id="@+id/bSignIn"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_marginLeft="16dp"
android:layout_weight="1"
android:background="@drawable/fragment_first_use_cloud_get_started_button_background"
android:focusable="true"
android:imeOptions="actionGo"
android:text="@string/login_screen_sign_in_button_text"
android:textColor="@color/Orange" />
</LinearLayout>
<LinearLayout
android:id="@+id/llFacebook"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/llSignUp"
android:gravity="right">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="8dp"
android:gravity="center"
android:text="@string/log_in_with_facebook"
android:textAppearance="@style/TextAppearance.AppCompat.Small.Inverse"
android:textColor="@android:color/white" />
<com.facebook.login.widget.LoginButton
android:id="@+id/bFacebookLogin"
android:layout_width="@dimen/circular_images_size_l"
android:layout_height="@dimen/circular_images_size_l"
android:background="@drawable/btnfbconnect"
android:text=""
android:textColor="@android:color/white"/>
</LinearLayout>
<!--Privacy-->
<ImageView
android:id="@+id/ivLockImage"
android:layout_width="@dimen/circular_images_size_l"
android:layout_height="@dimen/circular_images_size_l"
android:layout_alignParentLeft="true"
android:layout_below="@id/llFacebook"
android:layout_marginTop="18dp"
android:src="@drawable/iconshieldprivacy" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/llSignUp"
android:layout_alignParentRight="@+id/ivLockImage"
android:layout_alignRight="@+id/llSignUp"
android:layout_alignTop="@+id/ivLockImage"
android:layout_toRightOf="@+id/ivLockImage"
android:text="@string/login_screen_infi_privacy_title"
android:textColor="@android:color/white"
android:textSize="12sp"
android:textStyle="bold" />
<TextView
android:id="@+id/text1"
android:layout_width="241dp"
android:layout_height="wrap_content"
android:layout_alignEnd="@+id/textView2"
android:layout_alignRight="@+id/textView2"
android:layout_below="@+id/textView2"
android:layout_toRightOf="@+id/ivLockImage"
android:paddingTop="3dp"
android:text="@string/login_screen_infi_privacy_description"
android:textColor="@android:color/white"
android:textSize="10sp" />
<Space
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:layout_alignStart="@+id/text1"
android:layout_alignLeft="@+id/text1"
android:layout_below="@+id/text1"
android:layout_alignParentBottom="true" />
</RelativeLayout>
UPDATE: Это стиль xml:
<style name="TextLabel" parent="TextAppearance.AppCompat">
<!-- Hint color and label color in FALSE state -->
<item name="android:textColorHint">@android:color/white</item>
<item name="android:textColorHighlight">@android:color/white</item>
<item name="android:textColorLink">@android:color/white</item>
<item name="android:textSize">20sp</item>
<!-- Label color in TRUE state and bar color FALSE and TRUE State -->
<item name="colorAccent">@color/accent</item>
<item name="colorControlNormal">@android:color/white</item>
<item name="colorControlActivated">@color/accent</item>
</style>
Это исключение:
Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.infibond.infi/com.infibond.account.login.LoginActivity}: android.view.InflateException: Binary XML file line #22: Error inflating class EditText
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2281)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2359)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5230)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:780)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:596)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by android.view.InflateException: Binary XML file line #22: Error inflating class EditText
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.infibond.account.login.LoginFragment.onCreateView(LoginFragment.java:92)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:330)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:547)
at com.infibond.base.Inheritance.Activities.ActivityBase.onStart(ActivityBase.java:112)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
at android.app.Activity.performStart(Activity.java:5421)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2242)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2359)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5230)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:780)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:596)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by java.lang.UnsupportedOperationException: Can't convert to color: type=0x2
at android.content.res.TypedArray.getColor(TypedArray.java:327)
at android.widget.TextView.<init>(TextView.java:703)
at android.widget.EditText.<init>(EditText.java:61)
at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:60)
at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:56)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:101)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:938)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:992)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater$WrapperFactory2.onCreateView(CalligraphyLayoutInflater.java:280)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:172)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at uk.co.chrisjenx.calligraphy.CalligraphyLayoutInflater.inflate(CalligraphyLayoutInflater.java:60)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.infibond.account.login.LoginFragment.onCreateView(LoginFragment.java:92)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1962)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:330)
at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:547)
at com.infibond.base.Inheritance.Activities.ActivityBase.onStart(ActivityBase.java:112)
at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171)
at android.app.Activity.performStart(Activity.java:5421)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2242)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2359)
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5230)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:780)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:596)
at dalvik.system.NativeStart.main(NativeStart.java)
Кто-нибудь знает, почему это происходит и каков его правильный способ?
Спасибо заранее.
Ответ 1
Исправлена проблема с удалением parent="TextAppearance.AppCompat"
из конфигурации стиля:
Итак, теперь стиль выглядит следующим образом:
<style name="TextLabel">
<!-- Hint color and label color in FALSE state -->
<item name="android:textColorHint">@color/White</item>
<item name="android:textColorHighlight">@android:color/white</item>
<item name="android:textColorLink">@color/White</item>
<item name="android:textSize">20sp</item>
<!-- Label color in TRUE state and bar color FALSE and TRUE State -->
<item name="colorAccent">@color/accent</item>
<item name="colorControlNormal">@android:color/white</item>
<item name="colorControlActivated">@color/accent</item>
</style>
И в макете xml:
<android.support.design.widget.TextInputLayout
android:id="@+id/email_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/loginInfiLogoRL"
android:theme="@style/TextLabel">
<EditText
android:id="@+id/etUserName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/login_screen_email_hint"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:maxLines="1"
android:nextFocusDown="@+id/etPassword"
android:singleLine="true"
android:textColor="@android:color/white"
android:textColorHighlight="@color/White"
android:textColorHint="@android:color/white" />
</android.support.design.widget.TextInputLayout>
Ответ 2
Ваша проблема связана с другим xml
файлом. Я думаю, это потому, что в одном из ваших доступных файлов вы используете атрибут color
.
прочитайте здесь для получения дополнительной информации.