在fragment中使用PopupWindow,点击它区域外的地方,让其自动隐藏。
private PopupWindow popupWindow;
private void showPopWindow() {
if(popupWindow == null){
View pop_view = activity.getLayoutInflater().inflate(R.layout.popwin_order_list, null);
popupWindow = new PopupWindow(pop_view, UIUtils.dip2px(context,100), RelativeLayout.LayoutParams.WRAP_CONTENT,true);
initRadioButton(pop_view);
}
popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
popupWindow.setOutsideTouchable(true);//该属性设置为true,则在点击屏幕的空白位置也会退出
popupWindow.setFocusable(true);
popupWindow.setTouchable(true);
popupWindow.showAsDropDown(toolbar.getTvRight2(), -80, 0);
}
布局文件
.support.v4.app.FragmentTabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="@color/bottomTabBarColor">
"@+id/fl_tab_wrap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
.support.v4.app.FragmentTabHost>
代码初始化tabhost
private void initTabHost() {
layoutInflater = LayoutInflater.from(this);
mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.fl_home_content);
int count = mFragmentArray.length;
for(int i = 0; i < count; i++){
TabHost.TabSpec tabSpec = mTabHost.newTabSpec(context.getString(mTextviewArray[i])).setIndicator(getTabItemView(i));
mTabHost.addTab(tabSpec, mFragmentArray[i], null);
mTabHost.getTabWidget().setShowDividers((LinearLayout.SHOW_DIVIDER_NONE));
}
}
private View getTabItemView(int index){
View view = layoutInflater.inflate(R.layout.home_tab_item, null);
ImageView imageView = (ImageView) view.findViewById(R.id.iv_tab_icon);
imageView.setImageResource(mImageViewArray[index]);
return view;
}
如果,当某个fragment中切换其他fragment(不是tab对应的mFragmentArray中),返回就会crash。原因是什么?
--自定义对话框-->
public void showCommonDialog(final OnDialogBtnClickListener onDialogBtnClickListener) {
final Dialog dialog = new Dialog(context, R.style.dialog1);
//自定义布局文件 dialog.setContentView(R.layout.dialog_common_hint);
dialog.setCancelable(true);
btn_left = (Button) dialog.findViewById(R.id.btn_positive);
btnRight = (Button) dialog.findViewById(R.id.btn_negative);
TextView tv_description = (TextView)dialog.findViewById(R.id.tv_dialog_description);
tv_description.setText(description);
//左侧
btn_left.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onDialogBtnClickListener.onPositiveClick(v);
dialog.dismiss();
}
});
//右侧
btnRight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onDialogBtnClickListener.onNegativeClick(v);
dialog.dismiss();
}
});
dialog.show();
}
dialog对应的布局,添加一个圆角背景
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="10dp" />
<solid android:color="@color/common_bg" />
shape>
android:startColor=”@color/red” 为自定义开始颜色
为两头圆角的弧度,值越大越圆
为设置渐变色背景 angle 为角度
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape>
<corners android:radius="8.0dip" />
<gradient android:startColor="#EEEEEE" android:endColor="#EEEEEE"
android:angle="270.0" />
shape>
item>
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="0.0dip" />
<gradient android:startColor="@color/red" android:endColor="@color/red"
android:centerColor="@color/red" android:angle="270.0" />
shape>
clip>
item>
layer-list>
"@+id/pic_ProgressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="fill_parent"
android:visibility="gone"
android:layout_height="5dip"
android:progressDrawable="@drawable/myprogress_style">
//设置透明Theme,防止黑白屏,进入app闪烁
后退,直接返回桌面,并不退出应用。
@Override
public void onBackPressed() {
//super.onBackPressed();这句话要注掉,否则又去调用默认的back处理方式了
Intent mIntent = new Intent();
mIntent.setAction(Intent.ACTION_MAIN);
mIntent.addCategory(Intent.CATEGORY_HOME);
startActivity(mIntent);
}
视频缩略图类似,通过多媒体数据库获取。
private Bitmap getImageThumbBitmap(int ImageID, String path) {
Bitmap bitmap = null;
if (ImageID!=-1&&ImageID>0) {
bitmap = MediaStore.Images.Thumbnails.getThumbnail(
contentResolver, ImageID, MediaStore.Images.Thumbnails.MINI_KIND, null);
}
if (bitmap == null){
bitmap = MyFileUtils.getImageThumbnail(path, 80, 80);
}
return bitmap;
}
项目中要在string.xml 中显示特殊符号,如@号冒号等,直接写肯定不行啦。使用ASCII码进行显示。如:
@号 064;
:号 :
空格  
public void createNotification() {
String title = context.getString(R.string.notify_downloading_title)+fileName;
notification = new Notification(
R.mipmap.ic_launcher,//应用的图标
title,
System.currentTimeMillis());
notification.tickerText = title;
//notification.flags = Notification.FLAG_ONGOING_EVENT;
notification.flags = Notification.FLAG_AUTO_CANCEL;
contentView = new RemoteViews(context.getPackageName(),R.layout.notification_item);
contentView.setTextViewText(R.id.notificationTitle, title);
contentView.setTextViewText(R.id.notificationPercent, "0%");
contentView.setProgressBar(R.id.notificationProgress, 100, 0, false);
notification.contentView = contentView;
//点击后进入缓存列表
downloadIntent = new Intent(context, HomeActivity.class);
downloadIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
pendingIntent = PendingIntent.getActivity(context, 0, downloadIntent, 0);
notification.contentIntent = pendingIntent;
notificationManager = NotificationUtils.getManager(context);
}
IDE:android studio,eclipse
文本编辑器:Sublmine,Atom
版本控制:svn,git
笔记:为知笔记,有道云笔记,万象笔记
开发者学习常用站点:github,csdn,简书,掘金,推酷,慕课网
android大牛:一大堆,希望有你。