项目问题总结

来源:互联网 发布:找谱子的软件 编辑:程序博客网 时间:2024/06/05 16:30

在Android 7.0上PopupWindow.showAsDropDown不起作用的解决方法

public void show(View view) {    if (Build.VERSION.SDK_INT == 24) {        Rect rect = new Rect();        view.getGlobalVisibleRect(rect);        int h = view.getResources().getDisplayMetrics().heightPixels - rect.bottom;        setHeight(h);    }    showAsDropDown(view, 0, 0);}

Error:(16, 34) No resource found that matches the given name (at ‘layout_toLeftOf’ with value ‘@id/q

android:layout_toLeftOf里的id的控件要写在此id的前面

Parcelable encountered IOException writing serializable object

Intent intent = new Intent(LoginActivity.this, MainActivity.class);
intent.putExtra(“login”, loginModel);
startActivity(intent);
LoginModel类中的每个内部类都要事先Serializable接口

Unable to inflate view tag without class attribute

<View /> 写成<view />

Tablayout+ViewPager切换不相邻fragment时,总是重新onCreate

mViewPager.setOffscreenPageLimit(2);

SearchView改变光标、文字颜色

//searchview 文字颜色SearchView.SearchAutoComplete textView = (SearchView.SearchAutoComplete) searchview.findViewById(R.id.search_src_text);textView.setTextColor(Color.WHITE);//searchview 光标try {Class cls = Class.forName("android.support.v7.widget.SearchView");Field field = cls.getDeclaredField("mSearchSrcTextView");field.setAccessible(true);TextView tv = (TextView) field.get(searchview);Class[] clses = cls.getDeclaredClasses();for (Class cls_ : clses) {    Log.e("TAG", cls_.toString());    if (cls_.toString().endsWith("android.support.v7.widget.SearchView$SearchAutoComplete")) {        Class targetCls = cls_.getSuperclass().getSuperclass().getSuperclass().getSuperclass();        Field cuosorIconField = targetCls.getDeclaredField("mCursorDrawableRes");        cuosorIconField.setAccessible(true);        cuosorIconField.set(tv, R.drawable.cursor);    }}//下划线Field ownField = searchview.getClass().getDeclaredField("mSearchPlate");ownField.setAccessible(true);View mView = (View) ownField.get(searchview);mView.setBackgroundColor(Color.TRANSPARENT);

判断SearchView是否在搜索状态/展开状态

isIconified():Returns the current iconified state of the SearchView. @return true if the SearchView is currently iconified, false if the search field is fully visible.
svSearch.onActionViewCollapsed(); 收起搜索栏

ProgressDialog的dismiss和cancle方法不起作用

dialog.show(this, "", "message"); 使用dismiss和cancle关不了,因为它创建了一个新的dialog。

 /**     * Creates and shows a ProgressDialog.     *     * @param context the parent context     * @param title the title text for the dialog's window     * @param message the text to be displayed in the dialog     * @return the ProgressDialog     */    public static ProgressDialog show(Context context, CharSequence title,            CharSequence message) {        return show(context, title, message, false);    }//正确用法dialog = new ProgressDialog(this);dialog.setMessage("请稍后...");dialog.show();dialog.dismiss();//或者dialog = ProgressDialog.show(this, "", "message")
原创粉丝点击