android開發(fā)記錄

1. CheckBox的問題

checkbox用theme設(shè)置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跳轉(zhuǎn)和回退

//跳轉(zhuǎn)
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設(shè)置該屬性,stateAlwaysHidden表示鍵盤在Activity獲取焦點(diǎn)時隱藏.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搶占焦點(diǎn)問題

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解決重復(fù)添加問題

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

8.toolbar設(shè)置title

如果使用toolbar.setTilte,需要在setSupportActionBar之前調(diào)用才會生效。直接使用Activity的setTitle方法就可設(shè)置title。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容