一 設(shè)置標題欄 和 狀態(tài)欄相同背景色.
// 設(shè)置狀態(tài)欄和標題欄. 使用上面的增加和一個View
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
// 找到自定義的狀態(tài)欄.
LinearLayout layout_title = (LinearLayout) findViewById(R.id.ll_title_layout);
// 計算高度.
int statusH = FunctionTools.getStatusBarHeight(this.getApplicationContext());
int titleH = layout_title.getLayoutParams().height;
// 設(shè)置高度. 返回的是像素.
layout_title.getLayoutParams().height = titleH + statusH;
獲取狀態(tài)欄高度
/**
* 獲取高度.
* @param context
* @return
*/
public static int getStatusBarHeight(Context context){
int statusHeight = -1;
try {
Class clazz = Class.forName("com.android.internal.R$dimen");
Object object = clazz.newInstance();
int height = Integer.parseInt(clazz.getField("status_bar_height").get(object).toString());
statusHeight = context.getResources().getDimensionPixelSize(height);
} catch (Exception e){
e.printStackTrace();
}
return statusHeight;
}
布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="#FFDEAD"
android:id="@+id/ll_title_layout"
android:layout_width="match_parent"
android:layout_height="50dp">
<TextView
android:layout_width="match_parent"
android:id="@+id/tv_status_bar_tv"
android:layout_weight="1"
android:layout_height="0dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="@+id/btn_titlebar_qr_code"
style="@style/btn_titlebar_style"
android:text="二維碼"
/>
<TextView
android:id="@+id/tv_titlebar"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_gravity="center"
android:textAlignment="center"
android:paddingTop="10dp"
android:textSize="20sp"
android:text="標題"
android:layout_height="match_parent"/>
<Button
android:id="@+id/btn_titlebar_setting"
style="@style/btn_titlebar_style"
android:text="設(shè)置"/>
</LinearLayout>
</LinearLayout>
二 , 隱藏標題欄 和 狀態(tài)欄
(修改主題Style)
隱藏標題欄
<item name="windowNoTitle">true</item>
隱藏狀態(tài)欄(全屏)
<item name="android:windowFullscreen">true</item>
三 , 取消ListView 子控件的點擊事件.
// 通常我們用到的是第三種崇堵,即在Item布局的根布局加上下面屬性.
android:descendantFocusability=”blocksDescendants”
屬性解析
// viewgroup會優(yōu)先其子類控件而獲取到焦點
beforeDescendant
// viewgroup只有當其子類控件不需要獲取焦點時才獲取焦點
afterDescendant
// viewgroup會覆蓋子類控件而直接獲得焦點
blocksDescendants
如果出現(xiàn)CheckBox無法屏蔽的現(xiàn)象
// 可以自定義CheckBox 然后重寫他的onTouchEvent() 方法
// 返回false 說明不處理點擊事件.
@Override
public boolean onTouchEvent(MotionEvent event) {
return false;
}
popupWindow 點擊其他區(qū)域自動消失
// 設(shè)置為wrap_content
View contentView = LayoutInflater.from(getActivity()).inflate(R.layout.pw_conf_mode,null);
mConfModePW = new PopupWindow(contentView,WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,true);
// TODO : 不設(shè)置此屬性. 無法消失.
mConfModePW.setBackgroundDrawable(new BitmapDrawable());