Android 开发记录之UI篇(持续更新)
android.view.WindowManager.LayoutParams layoutParams = getWindow().getAttributes();layoutParams.gravity=Gravity.CENTER;
layoutParams.width= LayoutParams.MATCH_PARENT;
layoutParams.height= LayoutParams.WRAP_CONTENT;
getWindow().getDecorView().setPadding(0, 0, 0, 0);
getWindow().setAttributes(layoutParams);
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
AlertDialog.Builder builder = new AlertDialog.Builder(BaseActivity.this);
builder.setTitle(getString(R.string.device_pawd_new))
.setNegativeButton(getString(R.string.dialog_btn_cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//对话框消失
try {
Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
field.setAccessible( true );
// 将mShowing变量设为true,再去调用dismiss()对话框消失
field.set(dialog, true );
dialog.dismiss();
}catch (Exception e){
e.printStackTrace();
}
}
});
builder.setPositiveButton(getString(R.string.dialog_btn_confirm), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//对话框不消失
try {
Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
field.setAccessible( true );
// 将mShowing变量设为false,再去调用dismiss()对话框不消失
field.set(dialog, false );
dialog.dismiss();
}catch (Exception e){
e.printStackTrace();
}
}
});
设置背景图片,图片来源于drawable;
flightInfoPanel.setBackgroundDrawable(getResources().getDrawable(R.drawable.search_label_click));
转换字符串为int(颜色);
listItemView.deleteFilghtBg.setBackgroundColor(Color.parseColor("#F5F5DC"));
7.代码动态更改RadioButton的图片:
第一个方法:
setCompoundDrawablesWithIntrinsicBounds(Drawable left,Drawable top,Drawable right,Drawable bottom)
可以在上、下、左、右设置图标,如果不想在某个地方显示,则设置为null。图标的宽高将会设置为固有宽高,既自动通过getIntrinsicWidth和getIntrinsicHeight获取。
1 button = (RadioButton) group.getChildAt(i); 2 Resources res = TabTest.this.getResources(); 3 Drawable myImage = res.getDrawable(R.drawable.home); 4 button.setCompoundDrawablesWithIntrinsicBounds(null, myImage, null, null);
第二种方法:setCompoundDrawables(Drawable left, Drawable top, Drawable right, Drawable bottom)
可以在上、下、左、右设置图标,如果不想在某个地方显示,则设置为null。但是Drawable必须已经setBounds(Rect)。意思是你要添加的资源必须已经设置过初始位置、宽和高等信息。这个方法的好处就是不按比例,宽高可以打破原有的大小及比例!
1 Resources res = TabTest.this.getResources(); 2 Drawable myImage = res.getDrawable(R.drawable.home); 3 myImage.setBounds(1, 1, 100, 100); 4 button.setCompoundDrawables(null, myImage, null, null);
总结:
radiobutton设置不同方位的图标的方法有以上两种,如果想手动设置大小的话就要用setCompoundDrawables,事先要给Drawable设置setBounds。如果按照原有比例大小显示图片就使用setCompoundDrawablesWithIntrinsicBounds
8.上拉刷新下拉加载的通用View:走你
9.自定义View合集:自定义View