RadioButton和CheckBox使用
在代碼控制RadioButton的狀態(tài)进萄,狀態(tài)改了,但是UI沒有變磁玉,做法是使用CheckBox停忿。
如果有下圖這種需求,多個(gè)支付操作蚊伞,在切換的時(shí)候不想讓RadioButton有點(diǎn)擊操作席赂,而是通過控制外層ViewGroup的點(diǎn)擊來控制RadioButton的UI,需要設(shè)置RadioButton.setOnclickable(false)
<CheckBox
android:id="@+id/pay_radio_z"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="@drawable/radiobutton_background_selector"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:padding="@dimen/dp_10"
style="@android:style/Widget.DeviceDefault.Light.CompoundButton.RadioButton"/>
Android4.4及以上設(shè)置狀態(tài)欄指定顏色或者透明
/**
* 設(shè)置狀態(tài)欄顏色
*/
public static void setStatusBarColor(Activity activity,boolean isTranslucent) {
if (activity == null){
return;
}
String activityName = activity.getClass().getSimpleName();
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
View decorView = activity.getWindow().getDecorView();
int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
decorView.setSystemUiVisibility(option);
if (isTranslucent){
activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
}
else {
activity.getWindow().setStatusBarColor(ContextCompat.getColor(activity, R.color.colorAccent));
}
}
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// 生成一個(gè)狀態(tài)欄大小的矩形
View statusBarView = new View(activity);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
getStatusBarHeight(activity));
statusBarView.setLayoutParams(params);
if (isTranslucent){
statusBarView.setBackgroundColor(Color.TRANSPARENT);
}else {
statusBarView.setBackgroundColor(ContextCompat.getColor(activity, R.color.colorAccent));
}
// 添加 statusView 到布局中
ViewGroup decorView = (ViewGroup)activity.getWindow().getDecorView();
decorView.addView(statusBarView);
}
} catch (Exception e) {
e.printStackTrace();
LogUtil.e(TAG,"設(shè)置狀態(tài)欄透明異常时迫,方法名:setStatusBarColor");
}
}
/**
* 獲取手機(jī)狀態(tài)欄高度
* @param activity
* @return
*/
public static int getStatusBarHeight(Activity activity){
int resourceId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
int statusHeight = activity.getResources().getDimensionPixelSize(resourceId);
return statusHeight;
}
隱藏狀態(tài)欄
/**
* 設(shè)置指定界面全屏顯示
* @param context
*/
public static void setFullscreenMode(Activity context){
if (context != null) {
context.getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
Android中顏色透明度對(duì)應(yīng)16進(jìn)制值
<!--百分比-開頭字母-->
<!--100% —FF-->
<!--95% — F2-->
<!--90% — E6-->
<!--85% — D9-->
<!--80% — CC-->
<!--75% — BF-->
<!--70% — B3-->
<!--65% — A6-->
<!--60% — 99-->
<!--55% — 8C-->
<!--50% — 80-->
<!--45% — 73-->
<!--40% — 66-->
<!--35% — 59-->
<!--30% — 4D-->
<!--25% — 40-->
<!--20% — 33-->
<!--15% — 26-->
<!--10% — 1A-->
<!--5% — 0D-->
<!--0% — 00-->
android 移除棧中指定的activity
需求:MainActivity >> SecondActivity >> ThirdActivity >> HomeActivity颅停,SecondActivity 點(diǎn)擊返回回到MainActivity 。這個(gè)地方會(huì)有一個(gè)問題就是在進(jìn)入HomeActivity之后掠拳,點(diǎn)擊返回會(huì)回到MainActivity ,但是應(yīng)該是結(jié)束應(yīng)用才對(duì)癞揉。
如何在當(dāng)前頁(yè)面finish掉其他的界面呢,方法當(dāng)然會(huì)有很多溺欧,建議使用EventBus發(fā)送消息喊熟。
Android打開各種類型的文件、預(yù)覽不同類型的文件
/**
* 打開一個(gè)文件
*
* @param filePath
* 文件的絕對(duì)路徑
*/
private void openFile(final String filePath)
{
String ext = filePath.substring(filePath.lastIndexOf('.')).toLowerCase(Locale.US);
try
{
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
String temp = ext.substring(1);
String mime = mimeTypeMap.getMimeTypeFromExtension(temp);
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(filePath);
intent.setDataAndType(Uri.fromFile(file), mime);
startActivity(intent);
}
catch (Exception e)
{
e.printStackTrace();
Toast.makeText(getApplicationContext(), "無法打開后綴名為." + ext + "的文件姐刁!",
Toast.LENGTH_LONG).show();
}
}
原文地址:http://blog.csdn.net/eieihihi/article/details/45872051
Fragment動(dòng)態(tài)全屏
在activity中設(shè)置如下代碼芥牌,在對(duì)應(yīng)的fragment的setUserVisibleHint調(diào)用。
/**
* 控制是否全屏
* @param isfull
*/
public void setFullScreen(boolean isfull){
if (isfull){
getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
else {
WindowManager.LayoutParams attrs = getWindow()
.getAttributes();
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().setAttributes(attrs);
}
}