在Kitkat 4.4中的EditText上Longpress时应用程序崩溃

时间:2016-10-19 07:02:21

标签: android android-studio android-fragments

我在kitkat长按edittext时遇到了崩溃,但它对棒棒糖和棉花糖都有效..

下面是布局代码::

    <android.support.design.widget.TextInputLayout
    android:id="@+id/tip_address"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_centerVertical="true"
    android:layout_toLeftOf="@+id/img_address"
    android:hint="@string/address"
    app:hintTextAppearance="@style/EditTextHint">

    <EditText
        android:id="@+id/et_address"
        style="@style/EditTextWithBlackMediumSizeWithoutLeftAndTopPadding10"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@null" />
</android.support.design.widget.TextInputLayout>

使用::

的样式
    <style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="colorPrimary">@color/tab_selected_text_color</item>
    <item name="colorPrimaryDark">@color/tab_selected_text_color</item>
    <item name="colorAccent">@color/label_text_color</item>
    <item name="android:windowBackground">@color/windowBackground</item>
    <item name="android:typeface">normal</item>
    <item name="android:textColorHint">@color/label_input_color</item>
    <item name="android:shadowColor">@android:color/transparent</item>
    <item name="android:windowTitleBackgroundStyle">@style/WindowTitleBackground</item>
    <item name="android:colorAccent" tools:ignore="NewApi">@color/tab_selected_text_color</item>
</style>

build gradle ::

 compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
    applicationId "com.martinskiosk.martinskiosklvie"
    minSdkVersion 18
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}

请在此建议...

接收的异常是::

android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_menu_selectall_material.xml from drawable resource ID #0x7f02001e
at android.content.res.Resources.loadDrawable(Resources.java:2156)
at android.content.res.Resources.loadDrawable(Resources.java:2075)
at android.content.res.Resources.getDrawable(Resources.java:706)
at com.android.internal.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:388)
at com.android.internal.view.menu.ActionMenuItemView.initialize(ActionMenuItemView.java:110)
at com.android.internal.view.menu.ActionMenuPresenter.bindItemView(ActionMenuPresenter.java:198)
at com.android.internal.view.menu.BaseMenuPresenter.getItemView(BaseMenuPresenter.java:178)
at com.android.internal.view.menu.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:163)
at com.android.internal.view.menu.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:438)
at com.android.internal.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1052)
at com.android.internal.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:87)
at com.android.internal.view.menu.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:216)
at com.android.internal.view.menu.BaseMenuPresenter.getMenuView(BaseMenuPresenter.java:72)
at com.android.internal.view.menu.ActionMenuPresenter.getMenuView(ActionMenuPresenter.java:154)
at com.android.internal.widget.ActionBarContextView.initForMode(ActionBarContextView.java:230)
at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionMode(PhoneWindow.java:2425)
at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionModeForChild(PhoneWindow.java:2365)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
at android.view.View.startActionMode(View.java:4576)
at android.widget.Editor.startSelectionActionMode(Editor.java:1619)
at android.widget.Editor.performLongClick(Editor.java:883)
at android.widget.TextView.performLongClick(TextView.java:8666)
at android.view.View$CheckForLongPress.run(View.java:18677)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag vector
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:933)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
at android.content.res.Resources.loadDrawable(Resources.java:2152)
at android.content.res.Resources.loadDrawable(Resources.java:2075) 
at android.content.res.Resources.getDrawable(Resources.java:706) 
at com.android.internal.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:388) 
at com.android.internal.view.menu.ActionMenuItemView.initialize(ActionMenuItemView.java:110) 
at com.android.internal.view.menu.ActionMenuPresenter.bindItemView(ActionMenuPresenter.java:198) 
at com.android.internal.view.menu.BaseMenuPresenter.getItemView(BaseMenuPresenter.java:178) 
at com.android.internal.view.menu.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:163) 
at com.android.internal.view.menu.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:438) 
at com.android.internal.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1052) 
at com.android.internal.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:87) 
at com.android.internal.view.menu.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:216) 
at com.android.internal.view.menu.BaseMenuPresenter.getMenuView(BaseMenuPresenter.java:72) 
at com.android.internal.view.menu.ActionMenuPresenter.getMenuView(ActionMenuPresenter.java:154) 
at com.android.internal.widget.ActionBarContextView.initForMode(ActionBarContextView.java:230) 
at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionMode(PhoneWindow.java:2425) 
at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionModeForChild(PhoneWindow.java:2365) 
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665) 
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665) 
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665) 
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665) 
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665) 
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665) 
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665) 
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665) 
at android.view.View.startActionMode(View.java:4576) 
at android.widget.Editor.startSelectionActionMode(Editor.java:1619) 
at android.widget.Editor.performLongClick(Editor.java:883) 
at android.widget.TextView.performLongClick(TextView.java:8666) 
at android.view.View$CheckForLongPress.run(View.java:18677) 
at android.os.Handler.handleCallback(Handler.java:733) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:149) 
at android.app.ActivityThread.main(ActivityThread.java:5257) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) 
at dalvik.system.NativeStart.main(Native Method) 
10-19 12:38:50.940 29747-29747/com.martins.martinslvie.staging E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.martins.martinslvie.staging, PID: 29747
android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_menu_selectall_material.xml from drawable resource ID #0x7f02001e
at android.content.res.Resources.loadDrawable(Resources.java:2156)
at android.content.res.Resources.loadDrawable(Resources.java:2075)
at android.content.res.Resources.getDrawable(Resources.java:706)
at com.android.internal.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:388)
at com.android.internal.view.menu.ActionMenuItemView.initialize(ActionMenuItemView.java:110)
at com.android.internal.view.menu.ActionMenuPresenter.bindItemView(ActionMenuPresenter.java:198)
at com.android.internal.view.menu.BaseMenuPresenter.getItemView(BaseMenuPresenter.java:178)
at com.android.internal.view.menu.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:163)
at com.android.internal.view.menu.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:438)
at com.android.internal.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1052)
at com.android.internal.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:87)
at com.android.internal.view.menu.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:216)
at com.android.internal.view.menu.BaseMenuPresenter.getMenuView(BaseMenuPresenter.java:72)
at com.android.internal.view.menu.ActionMenuPresenter.getMenuView(ActionMenuPresenter.java:154)
at com.android.internal.widget.ActionBarContextView.initForMode(ActionBarContextView.java:230)
at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionMode(PhoneWindow.java:2425)
at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionModeForChild(PhoneWindow.java:2365)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665)
at android.view.View.startActionMode(View.java:4576)
at android.widget.Editor.startSelectionActionMode(Editor.java:1619)
at android.widget.Editor.performLongClick(Editor.java:883)
at android.widget.TextView.performLongClick(TextView.java:8666)
at android.view.View$CheckForLongPress.run(View.java:18677)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:149)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
at dalvik.system.NativeStart.main(Native Method)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag vector
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:933)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
at android.content.res.Resources.loadDrawable(Resources.java:2152)
at android.content.res.Resources.loadDrawable(Resources.java:2075) 
at android.content.res.Resources.getDrawable(Resources.java:706) 
at com.android.internal.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:388) 
at com.android.internal.view.menu.ActionMenuItemView.initialize(ActionMenuItemView.java:110) 
at com.android.internal.view.menu.ActionMenuPresenter.bindItemView(ActionMenuPresenter.java:198) 
at com.android.internal.view.menu.BaseMenuPresenter.getItemView(BaseMenuPresenter.java:178) 
at com.android.internal.view.menu.ActionMenuPresenter.getItemView(ActionMenuPresenter.java:163) 
at com.android.internal.view.menu.ActionMenuPresenter.flagActionItems(ActionMenuPresenter.java:438) 
at com.android.internal.view.menu.MenuBuilder.flagActionItems(MenuBuilder.java:1052) 
at com.android.internal.view.menu.BaseMenuPresenter.updateMenuView(BaseMenuPresenter.java:87) 
at com.android.internal.view.menu.ActionMenuPresenter.updateMenuView(ActionMenuPresenter.java:216) 
at com.android.internal.view.menu.BaseMenuPresenter.getMenuView(BaseMenuPresenter.java:72) 
at com.android.internal.view.menu.ActionMenuPresenter.getMenuView(ActionMenuPresenter.java:154) 
at com.android.internal.widget.ActionBarContextView.initForMode(ActionBarContextView.java:230) 
at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionMode(PhoneWindow.java:2425) 
at com.android.internal.policy.impl.PhoneWindow$DecorView.startActionModeForChild(PhoneWindow.java:2365) 
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665) 
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665) 
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665) 
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665) 
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665) 
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665) 
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665) 
at android.view.ViewGroup.startActionModeForChild(ViewGroup.java:665) 
at android.view.View.startActionMode(View.java:4576) 
at android.widget.Editor.startSelectionActionMode(Editor.java:1619) 
at android.widget.Editor.performLongClick(Editor.java:883) 
at android.widget.TextView.performLongClick(TextView.java:8666) 
at android.view.View$CheckForLongPress.run(View.java:18677) 
at android.os.Handler.handleCallback(Handler.java:733) 
at android.os.Handler.dispatchMessage(Handler.java:95) 
at android.os.Looper.loop(Looper.java:149) 
at android.app.ActivityThread.main(ActivityThread.java:5257) 
at java.lang.reflect.Method.invokeNative(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:515) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) 
at dalvik.system.NativeStart.main(Native Method) 

Javacode:

public class SignInActivity extends Activity implements TextWatcher, View.OnFocusChangeListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_signin);
    ButterKnife.bind(this);
    addTextWatcher();
    addFocusListener();

    KeyBoard.showKeyboard(nameEditTextViews.get(0), SignInActivity.this);
}

@Override
protected void onPause() {
    super.onPause();
    KeyBoard.hideKeyboard(nameEditTextViews.get(0), SignInActivity.this);
}

private void validateEmailFails() {
    checkingEmail();

}

private void validateEmailClear() {
    emailFocusOut();
}

private void validatePasswordFails() {
    checkingPwd();
}

private void validatePasswordClear() {
    passwordFocusOut();
}


private void addTextWatcher() {
    for (int i = 0; i < nameEditTextViews.size(); i++) {
        nameEditTextViews.get(i).addTextChangedListener(this);
    }
}

private void addFocusListener() {
    for (int i = 0; i < nameEditTextViews.size(); i++) {
        nameEditTextViews.get(i).setOnFocusChangeListener(this);
    }
}

private boolean validateAllEditFields(boolean empty_validation) {
    boolean email_status = false, pwd_status = false, status = false;
    for (int j = 0; j < nameEditTextViews.size(); j++) {
        if (nameEditTextViews.get(j).getText().toString().matches("")) {
            if (nameEditTextViews.get(j).getId() == R.id.et_email) {
                if (empty_validation) {
                    validateEmailFails();
                    email_status = false;
                } else {
                    validateEmailClear();
                    email_status = false;
                }
            } else if (nameEditTextViews.get(j).getId() == R.id.et_password) {
                if (empty_validation) {
                    validatePasswordFails();
                    pwd_status = false;
                } else {
                    validatePasswordClear();
                    pwd_status = false;
                }
            }
        } else {
            if (nameEditTextViews.get(j).getId() == R.id.et_email) {
                if (Constants.isValidEmail(nameEditTextViews.get(j).getText().toString().trim())) {
                    validateEmailClear();
                    email_status = true;
                } else {
                    validateEmailFails();
                    email_status = false;
                }
            } else if (nameEditTextViews.get(j).getId() == R.id.et_password) {
                if (Constants.isValidPassword(nameEditTextViews.get(j).getText().toString().trim())) {
                    validatePasswordClear();
                    pwd_status = true;
                } else {
                    validatePasswordFails();
                    pwd_status = false;
                }
            }
        }

        if (pwd_status == true && email_status == true) {
            status = true;
        } else {
            status = false;
        }
    }
    return status;
}

@OnClick({R.id.tv_skip, R.id.tv_no_account, R.id.tv_signIn})
public void pickDoor(View v) {
    if (v.getId() == R.id.tv_skip) {
        startActivity(new Intent(this, HomeSceeenActivity.class));
        finish();
    } else if (v.getId() == R.id.tv_no_account) {
        Intent i = new Intent(this, SignUpActivity.class);
        i.putExtra("FromWhere", "sign");
        startActivity(i);
        finish();
    } else if (v.getId() == R.id.tv_signIn) {
        Boolean status = validateAllEditFields(true);
    }
}

@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

}

@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
    //   Boolean status = validateAllEditFields(false);

}

@Override
public void afterTextChanged(Editable editable) {

}

@Override
public void onBackPressed() {
    if (pDialog != null) {
        if (pDialog.isShowing()) {
            pDialog.dismiss();
        }
    } else {
       // startActivity(new Intent(SignInActivity.this, StartUpActivity.class));
        finish();
    }
    super.onBackPressed();
}

@Override
public void onFocusChange(View v, boolean hasFocus) {
    if (v.getId() == R.id.et_email && hasFocus) {
        tip_layouts.get(0).setHint(getResources().getString(R.string.email).toUpperCase());
        emailFocusIn();
    } else if (v.getId() == R.id.et_email && !hasFocus) {
        if (nameEditTextViews.get(0).getText().toString().matches("")) {
            tip_layouts.get(0).setHint(getResources().getString(R.string.email));
        } else {
            tip_layouts.get(0).setHint(getResources().getString(R.string.email).toUpperCase());
        }
        //  emailFocusOut();
    } else if (v.getId() == R.id.et_password && hasFocus) {
        tip_layouts.get(1).setHint(getResources().getString(R.string.pwd).toUpperCase());
        passwordFocusIn();
        checkingEmail();
    } else if (v.getId() == R.id.et_password && !hasFocus) {
        if (nameEditTextViews.get(1).getText().toString().matches("")) {
            tip_layouts.get(1).setHint(getResources().getString(R.string.pwd));
        } else {
            tip_layouts.get(1).setHint(getResources().getString(R.string.pwd).toUpperCase());
        }
        checkingPwd();
    }
}

private void checkingPwd() {
    if (!Constants.isEditTextEmpty(nameEditTextViews.get(1))) {
        if (Constants.isValidPassword(nameEditTextViews.get(1).getText().toString())) {
            passwordFocusOut();
        } else {
            passwordFocusIn();
            nameValidateTextViews.get(1).setVisibility(View.GONE);
            nameValidateTextViews.get(1).setText(getResources().getString(R.string.invalid_pwd));
        }
    } else {
        passwordFocusIn();
        nameValidateTextViews.get(1).setVisibility(View.GONE);
        nameValidateTextViews.get(1).setText(getResources().getString(R.string.enter_pwd));
    }
}

private void checkingEmail() {
    if (!Constants.isEditTextEmpty(nameEditTextViews.get(0))) {
        if (Constants.isValidEmail(nameEditTextViews.get(0).getText().toString())) {
            emailFocusOut();
        } else {
            emailFocusIn();
            nameValidateTextViews.get(0).setVisibility(View.VISIBLE);
            nameValidateTextViews.get(0).setText(getResources().getString(R.string.invalid_email));
        }
    } else {
        emailFocusIn();
        nameValidateTextViews.get(0).setVisibility(View.VISIBLE);
        nameValidateTextViews.get(0).setText(getResources().getString(R.string.enter_email));
    }
}

private void emailFocusIn() {
    tip_layouts.get(0).setHintTextAppearance(R.style.EditTextHintError);
    viewsList.get(0).setBackgroundColor(ContextCompat.getColor(this, R.color.tab_selected_text_color));
    nameValidateTextViews.get(0).setVisibility(View.INVISIBLE);
}

private void emailFocusOut() {
    tip_layouts.get(0).setHintTextAppearance(R.style.EditTextHint);
    viewsList.get(0).setBackgroundColor(ContextCompat.getColor(this, R.color.light_divider_white_bg));
    nameValidateTextViews.get(0).setVisibility(View.INVISIBLE);
}

private void passwordFocusIn() {
    tip_layouts.get(1).setHintTextAppearance(R.style.EditTextHintError);
    viewsList.get(1).setBackgroundColor(ContextCompat.getColor(this, R.color.tab_selected_text_color));
    nameValidateTextViews.get(1).setVisibility(View.GONE);
}

private void passwordFocusOut() {
    tip_layouts.get(1).setHintTextAppearance(R.style.EditTextHint);
    viewsList.get(1).setBackgroundColor(ContextCompat.getColor(this, R.color.light_divider_white_bg));
    nameValidateTextViews.get(1).setVisibility(View.GONE);
}

}

1 个答案:

答案 0 :(得分:1)

你的问题不在onLongPress上

Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag vector

这是XML解析问题