我的代码实际上存在这个问题,但是当编辑文本为空时我设置了一些要显示的文本。当我按下登录按钮时,我的应用程序崩溃了。这是错误:
android.view.InflateException:二进制XML文件行#17:二进制XML 文件行#17:错误膨胀类TextView 引起:android.view.InflateException:二进制XML文件行#17:错误膨胀类TextView 引起:java.lang.UnsupportedOperationException:无法解析索引4处的属性:TypedValue {t = 0x2 / d = 0x1010099 α= 1}
这是我的xml代码:
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="56dp"
android:paddingLeft="24dp"
android:paddingRight="24dp">
<ImageView android:src="@drawable/logo"
android:layout_width="wrap_content"
android:layout_height="72dp"
android:layout_marginBottom="24dp"
android:layout_gravity="center_horizontal" />
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:id="@+id/input_username_id"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:theme="@style/TextLabel"
android:layout_marginBottom="20dp">
<EditText
android:id="@+id/input_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:hint="@string/hint_username"
android:inputType="textEmailAddress"
android:layout_marginRight="10dp"
android:gravity="right" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/input_password_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="20dp"
android:theme="@style/TextLabel">
<EditText
android:id="@+id/input_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:hint="@string/hint_password"
android:inputType="textPassword" />
</android.support.design.widget.TextInputLayout>
<android.support.v7.widget.AppCompatButton
android:id="@+id/btn_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="35dp"
android:layout_marginBottom="40dp"
android:padding="12dp"
android:paddingLeft="30dp"
android:background="@drawable/my_button"
android:drawableLeft="@drawable/ic_stat_login"
android:textColor="@color/white"
android:text="ورود"/>
<TextView android:id="@+id/link_signup"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginBottom="24dp"
android:layout_marginTop="10dp"
android:textColor="@color/white"
android:text="create an account"
android:gravity="center"
android:textSize="13dp"
/>
<TextView android:id="@+id/link_forgetpass"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_marginBottom="24dp"
android:layout_marginTop="10dp"
android:textColor="@color/white"
android:text="forget my password"
android:gravity="center"
android:textSize="13dp"
/>
</LinearLayout>
这是我的java代码:
_emailText = (EditText) (findViewById(R.id.input_email));
_passwordText = (EditText) (findViewById(R.id.input_password));
_loginButton = (Button) (findViewById(R.id.btn_login));
_loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
login();
}
});
public void login() {
Log.d(TAG, "Login");
if (!validate()) {
onLoginFailed();
return;
}
email = _emailText.getText().toString();
String password = _passwordText.getText().toString();
JsonObject json = new JsonObject();
json.addProperty("email", email);
json.addProperty("password", password);
_loginButton.setEnabled(false);
WebService.connect(LoginActivity.this, json, "login",layout_for_progressbar);
}
public boolean validate() {
boolean valid = true;
String email = _emailText.getText().toString();
String password = _passwordText.getText().toString();
if (email.isEmpty() || !android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
_emailText.setError("Wrong Email");
valid = false;
} else {
_emailText.setError(null);
}
if (password.isEmpty() || password.length() < 6 || password.length() > 15) {
Typeface fontt = Typeface.createFromAsset(getAssets(),"fonts/ir.ttf");
SpannableStringBuilder ssbuilder=new SpannableStringBuilder("Pass between 5 to 16");
ssbuilder.setSpan(new CustomTypefaceSpan("",fontt),0,ssbuilder.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
_passwordText.setError(ssbuilder);
valid = false;
} else {
_passwordText.setError(null);
}
return valid;
}
这是我的style.xml:
<style name="TextLabel" parent="TextAppearance.AppCompat">
<!-- Hint color and label color in FALSE state -->
<item name="android:textColorHint">@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/white</item>
<item name="colorControlNormal">@color/white</item>
<item name="colorControlActivated">@color/white</item>
</style>
答案 0 :(得分:3)
问题是我设置它的样式的父亲应该是
parent="Theme.AppCompat.Light.NoActionBar"