Android 开发笔记

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

布局文件


        
    

代码初始化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,对话框问题


    
 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对应的布局,添加一个圆角背景



    
    

4,水平进度条

1、新建 myprogress_style.xml在drawable中

android:startColor="@color/red" 为自定义开始颜色
<**corners**** android:radius="0.0dip" /> 为两头圆角的弧度,值越大越圆
<
gradient**** **> 为设置渐变色背景 angle 为角度




 
 
 
 


 
 
  
  
 
 


2、应用样式


5,splash首屏加载黑屏问题

//设置透明Theme,防止黑白屏,进入app闪烁


6,物理后退模拟点击Home键

后退,直接返回桌面,并不退出应用。

@Override
public 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大牛:一大堆,希望有你。

你可能感兴趣的:(Android 开发笔记)