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

布局文件

<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" 为自定义开始颜色
<**corners**** android:radius="0.0dip" /> 为两头圆角的弧度,值越大越圆
<
gradient**** **> 为设置渐变色背景 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键

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

@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码进行显示。如:

@号 &#064; 
:号 &#058; 
空格 &#160; 

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 156,757评论 4 359
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 66,478评论 1 289
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 106,540评论 0 237
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 43,593评论 0 203
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 51,903评论 3 285
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,329评论 1 210
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,659评论 2 309
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,383评论 0 195
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,055评论 1 238
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,337评论 2 241
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 31,864评论 1 256
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,227评论 2 251
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 32,820评论 3 231
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 25,999评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,750评论 0 192
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,365评论 2 269
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,260评论 2 258

推荐阅读更多精彩内容