Android 开发笔记
来源:互联网 发布:linux 命令 ls l 编辑:程序博客网 时间:2024/06/07 03:20
1,PopupWindow消失的问题
在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); }
2,FragmentTabHost切换其它fragment,后退crash
布局文件
<android.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"> <FrameLayout android:id="@+id/fl_tab_wrap" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </android.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。原因是什么?
3,对话框问题
<!--自定义对话框--> <style name="dialog1" parent="@android:style/Theme.Dialog"> <item name="android:windowFrame">@null</item><!--边框--> <item name="android:windowIsFloating">true</item><!--是否浮现在activity之上--> <item name="android:windowIsTranslucent">true</item><!--半透明--> <item name="android:windowNoTitle">true</item><!--无标题--> <item name="android:windowBackground">@android:color/darker_gray</item><!--背景透明--> <item name="android:backgroundDimEnabled">true</item><!--背景变暗--> </style>
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对应的布局,添加一个圆角背景
<?xml version="1.0" encoding="utf-8"?><shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <corners android:radius="10dp" /> <solid android:color="@color/common_bg" /></shape>
4,水平进度条
1、新建 myprogress_style.xml在drawable中
android:startColor=”@color/red” 为自定义开始颜色
为两头圆角的弧度,值越大越圆
为设置渐变色背景 angle 为角度
<?xml version="1.0" encoding="UTF-8"?><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>
2、应用样式
<ProgressBar android:id="@+id/pic_ProgressBar"style="?android:attr/progressBarStyleHorizontal" android:layout_width="fill_parent" android:visibility="gone" android:layout_height="5dip"android:progressDrawable="@drawable/myprogress_style">
5,splash首屏加载黑屏问题
//设置透明Theme,防止黑白屏,进入app闪烁
<style name="Theme.AppTranslucent" parent="android:Theme"> <item name="android:windowIsTranslucent">true</item> <item name="android:windowNoTitle">true</item> </style>
6,物理后退模拟点击Home键
后退,直接返回桌面,并不退出应用。
@Overridepublic void onBackPressed() { //super.onBackPressed();这句话要注掉,否则又去调用默认的back处理方式了 Intent mIntent = new Intent(); mIntent.setAction(Intent.ACTION_MAIN); mIntent.addCategory(Intent.CATEGORY_HOME); startActivity(mIntent);}
7,根据android文件ID,查找缩略图
视频缩略图类似,通过多媒体数据库获取。
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; }
8,string.xml中不能有特殊符号
项目中要在string.xml 中显示特殊符号,如@号冒号等,直接写肯定不行啦。使用ASCII码进行显示。如:
@号 @ :号 : 空格  
9,Android自定义通知栏
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); }
10,Android常用工具,其他相关
IDE:android studio,eclipse
文本编辑器:Sublmine,Atom
版本控制:svn,git
笔记:为知笔记,有道云笔记,万象笔记
开发者学习常用站点:github,csdn,简书,掘金,推酷,慕课网
android大牛:一大堆,希望有你。
0 0
- [Android]Android开发笔记
- android开发笔记 -摄像头开发
- Android 开发笔记
- Android 开发笔记
- Android开发笔记
- android sqlite开发笔记
- Android 开发笔记
- Android开发笔记: Activity
- Android开发笔记: Menu
- 菜鸟Android开发笔记
- Android开发笔记-简介
- Android 开发笔记
- Android开发学习笔记
- Android开发学习笔记
- Android开发学习笔记
- Android开发FAQ笔记
- 《Android系统开发》笔记
- Android 开发笔记
- margin、edge
- 零基础学习网页制作(一)
- 21、Bitmap二次采样
- studio虚拟机乱码问题
- 跨多个RecyclerView拖动排序
- Android 开发笔记
- listview
- 手机拍摄功能详解
- P2P、P2C、O2O、B2C、B2B、C2C 的区别
- 对list对象进行去重操作,并排序
- Java导出excel(无模板导出excel)
- Arm Linux系统调用流程详细解析-SWI
- .net平台下C#socket通信(上)
- 孔子的学费