美文网首页
android开发记录

android开发记录

作者: nicegoing | 来源:发表于2016-06-19 08:27 被阅读67次

    1. CheckBox的问题

    checkbox用theme设置style

    <CheckBox 
       android:layout_width="wrap_content"
       android:layout_height="wrap_content" 
       android:checked="true"
       android:text="Check Box" 
       android:theme="@style/MyCheckBox"/>
    

    2.Fragment跳转和回退

    //跳转
    FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    fragmentTransaction.replace(((BaseActivity) getActivity()).getFragmentContainerViewId(), fragment);
    fragmentTransaction.addToBackStack(null);fragmentTransaction.commit();
    
    //回退
     @Override
        public void onResume() {
    
            super.onResume();
    
            getView().setFocusableInTouchMode(true);
            getView().requestFocus();
            getView().setOnKeyListener(new View.OnKeyListener() {
                @Override
                public boolean onKey(View v, int keyCode, KeyEvent event) {
    
                    if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
                        getActivity().getSupportFragmentManager().popBackStack();
                        return true;
                    }
                    return false;
                }
            });
        }
    

    3.Fragment切换重叠问题

    https://github.com/nicegoing/FragmentDemo

    4. 键盘挡住输入框问题

    Activity设置该属性,stateAlwaysHidden表示键盘在Activity获取焦点时隐藏.adjustResize表示软键盘弹出时,Activity的窗口大小改变。这样Activity的ScrollView不能显示完全,可以滑动。
    android:windowSoftInputMode="stateAlwaysHidden|adjustResize"
    
    <ScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true">
    
            <!-- Other Views -->
    </ScrollView>
    

    5. inflate的context问题

    使用application使用的是application的主题,使用activity使用的是activity的主题。

    6. EditText抢占焦点问题

    In case the view is the first EditText it seems clearFocus() clears its focus but then starts searching for a focus candidate through the view tree and then finds out the same view. And the result is the same. But if you put android:focusableInTouchMode the focus traversal ends up on its parent.
    

    7.DialogFragment解决重复添加问题

        private void showAllowingStateLoss(@NonNull FragmentManager manager, String tag) {
            final FragmentTransaction transaction = manager.beginTransaction();
            transaction.remove(this);
            transaction.add(this, tag);
            transaction.commitAllowingStateLoss();
        }
    

    8.toolbar设置title

    如果使用toolbar.setTilte,需要在setSupportActionBar之前调用才会生效。直接使用Activity的setTitle方法就可设置title。

    相关文章

      网友评论

          本文标题:android开发记录

          本文链接:https://www.haomeiwen.com/subject/vacyrttx.html