1实苞、AppCompatActivity去掉ActionBar
當(dāng)使用BaseActivity繼承AppCompatActivity時(shí)辆飘,使用原始方法 requestWindowFeature(Window.FEATURE_NO_TITLE); 無法去掉標(biāo)題欄
原因:AppCompatActivity在Android5.0之后出現(xiàn)睦霎,是用來替換ActionBarActivity的,因此AppCompatActivity中只有ActionBar檬洞,沒有標(biāo)題欄
解決方式:
getSupportActionBar().hide();
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
2屈呕、首頁下拉刷新時(shí),每次下拉刷新之后都會(huì)跳到ListView頂部珠叔,這是因?yàn)槊看嗡⑿聲r(shí)都會(huì)去請(qǐng)求數(shù)據(jù)蝎宇,而請(qǐng)求數(shù)據(jù)完成后會(huì)調(diào)用onModeChange()方法,在這個(gè)方法中祷安,我給ListView設(shè)置數(shù)據(jù)使用的時(shí)new HomeLiveAdapter()姥芥,每次重新設(shè)置Adapter時(shí),ListView都會(huì)重新回到頂部汇鞭,因此這樣改了一下代碼凉唐,問題解決。當(dāng)?shù)谝淮芜M(jìn)來的時(shí)候霍骄,livePage == 1 這個(gè)時(shí)候去new Adapter 第二次 三次進(jìn)來時(shí)台囱,直接提醒a(bǔ)dpter更新數(shù)據(jù)即可。
3读整、動(dòng)態(tài)申請(qǐng)權(quán)限時(shí)簿训,在Fragment中申請(qǐng)權(quán)限,onRequetsPermission()方法未被調(diào)用米间,這是因?yàn)樵贏ctivity和Fragment中調(diào)用requestPermissions()方法是不同的强品,F(xiàn)ragment要自己調(diào)用該方法
4.點(diǎn)擊EditTex不彈出軟鍵盤的方法:editEdit.setInputType(InputType.TYPE_NULL);? 這個(gè)方法不光不會(huì)彈出軟鍵盤,還會(huì)使EditText失去焦點(diǎn)屈糊。
另外 EditText默認(rèn)點(diǎn)擊兩次才會(huì)響應(yīng)onClick方法的榛,解決方法:在xml文件中設(shè)置:
android:clickable="true"http://允許單擊
android:focusableInTouchMode="false"http://不獲得焦點(diǎn),此時(shí)會(huì)觸發(fā)onclick事件
如果需要同時(shí)獲得焦點(diǎn)逻锐,則在onclick處理中添加如下代碼
(EditText) mEditText=(EditText)v;
mEditText.setFocusable(true);
mEditText.setFocusableInTouchMode(true);
mEditText.requestFocus();
mEditText.requestFocusFromTouch();
還要自動(dòng)彈出軟鍵盤夫晌?!加入以下2行就行啦
InputMethodManagerinputManager =
(InputMethodManager)mEditText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.showSoftInput(mEditText, 0);
4.ImageView在代碼中設(shè)置圖片
imageView.setImageResoure()/.setImageDrawable();這在xml中相當(dāng)于設(shè)置src 前景
imageView.setBackgroud();這在xml相當(dāng)于設(shè)置background 背景
5.啟動(dòng)時(shí) 白屏問題 項(xiàng)目啟動(dòng)時(shí)谦去,可能會(huì)去找背景顏色因此給SplashActivity設(shè)置一個(gè)主題 設(shè)置windowBackground屬性為啟動(dòng)頁的圖片即可
? ? true? ? @null? ? @drawable/logo_splash? ? true
6.父類的構(gòu)造方法最先調(diào)用慷丽。
7.如果出現(xiàn) Binary XML file line #0: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference 類似于這種異常,一般來說鳄哭,可能是<View />中的view寫成了小寫要糊。
8.ScrollView與底部布局的嵌套。底部布局一直置于底部妆丘,不會(huì)隨著ScrollView的滑動(dòng)而滑動(dòng)锄俄。
<LinearLayout android:orientation="vertical">
<ScrollView height = "0dp" weight = "1"></ScrollView>
<底部布局></>
</LinearLayout>
如上。最外層LinearLayout?? 里面ScrollView高度設(shè)置為0 weight設(shè)置為1? 占滿底部布局外的所有位置勺拣。
9.在utils類中定義一個(gè)靜態(tài)的dialog 編輯一個(gè)靜態(tài)方法使之彈出奶赠,在頁面中使用時(shí)報(bào)了這樣一個(gè)錯(cuò):
Unable to add window -- token android.os.BinderProxy@9e87e8f is not valid; is your activity running?
此時(shí)需要在創(chuàng)建dialog時(shí)添加一句代碼
Window dialogWindow = kefuDialog.getWindow();dialogWindow.setType(WindowManager.LayoutParams .TYPE_SYSTEM_ALERT);
why?以后再查
10.ShareSDK分享自定義九宮格药有。
點(diǎn)擊分享鍵毅戈,彈出九宮格苹丸。在九宮格點(diǎn)擊事件中添加指定平臺(tái)分享的代碼即可。
11.如果有嵌套滑動(dòng)時(shí)苇经,使用NestedScrollView赘理。(后續(xù)更新)
12.View.inflate(),在RecyclerView中扇单,item的inflate需要添加root參數(shù)商模,不然在布局文件中設(shè)置的控件寬高將失效:參考
http://www.reibang.com/p/9a6db88b8ad3里面對(duì)inflate 和 RecyclerView源碼的分析,通過分析inflate()的源碼蜘澜,發(fā)現(xiàn)如果不添加root施流,那么就不會(huì)有LayoutParams,那么RecyclerView的LayoutManager就會(huì)實(shí)現(xiàn)generateDefaultLayoutParams()這個(gè)方法鄙信,這個(gè)方法是這樣寫的
/** * {@inheritDoc} */
@Override
publicLayoutParamsgenerateDefaultLayoutParams(){
return? new? LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
}
也就是說瞪醋,如果不添加root,無論設(shè)置的寬高是多少扮碧,最終的結(jié)果都是WRAP_CONTENT趟章。
所以在RecyclerView中 item inflate xml最好是使用LayoutInflater.from(parent.getContext()).inflate(id,parent,false); 這樣一句代碼 注意最后一個(gè)參數(shù)必須為false。不然會(huì)包這樣的錯(cuò):
The specified child already has a parent. You must call removeView() on the child's parent first.
在inflate方法中有這樣一句代碼:
if (root != null && attachToRoot) {
root.addView(temp, params);
}
就是說慎王,如果root蚓土!=null && attachToRoot為true,那么會(huì)執(zhí)行root.addView()赖淤,而RecyclerView/ListView會(huì)自動(dòng)將child添加到它里面去蜀漆,所以會(huì)報(bào)兩個(gè)parent的錯(cuò)。
但是咱旱,如果Item中寫了父容器确丢,如LinearLayout等,就不會(huì)有無法設(shè)置寬高的問題了吐限。
13.RecyclerView展示多種布局:
13.1.重寫getItemViewType()
13.2要寫幾種布局鲜侥,就創(chuàng)建幾種ViewHolder
在onCreateViewHolder()方法中使用
13.3 在onBindViewHolder中填充數(shù)據(jù)