Skip to content

Commit

Permalink
Add more note
Browse files Browse the repository at this point in the history
  • Loading branch information
CharonChui committed Mar 31, 2014
1 parent c6e2729 commit c476919
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 1 deletion.
47 changes: 47 additions & 0 deletions Android基础知识/PopupWindow响应back按键并关闭.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
PopupWindow响应back按键并关闭
===

`PopupWindow`跟我们的`Activity`不一样,因为我们在构造时往往不是继承来的,而是`new`出来的。所以不能使用重写`onKeyDown()`之类的方法来截获键盘事件。

1. 最简单
`new`的时候,使用下面的方法:
`new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);`关键在于最后一个参数,`Focusable`属性,让它能够接受焦点。
当然你也可以手动设置它:
`PW.setFocusable(true);`
`PW.setFocusableInTouchMode(true);` //为了保险起见加上这句
此时实际上还是不能起作用的,百度给出的结论是,必须加入下面这行作用未知的语句才能发挥作用:
`pw.setBackgroundDrawable(new BitmapDrawable());` // 响应返回键必须的语句
请放心,设置 `BackgroundDrawable`并不会改变你在配置文件中设置的背景颜色或图像。

2. 最通用
首先在布局文件`(*.xml)`中随意选取一个不影响任何操作的`View`,推荐使用最外层的`Layout`
然后设置该`Layout``Focusable``FocusableInTouchMode`都为`true`
接着回到代码中对该`View`重写`OnKeyListener()`事件了。捕获`KEYCODE_BACK`给对话框`dismiss()`
给出一段示例:
```java
private PopupWindow pw;
private View view;
private LinearLayout layMenu;

LayoutInflater inflater = (LayoutInflater) main.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.popup_main_menu, null, false);
layMenu = (LinearLayout) view.findViewById(R.id.layMenu);
pw = new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);

layMenu.setOnKeyListener(new OnKeyListener()
{
public boolean onKey(View v, int keyCode, KeyEvent event)
{
if (event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_BACK)
pw.dismiss();

return false;
}
});
```
上面两种方法的代码可以并存,当然如果使用第一种方法的话就不需要再捕获返回键了,不过你可以尝试捕获其他你需要的按键

---

- 邮箱 :[email protected]
- Good Luck!
3 changes: 2 additions & 1 deletion Android基础知识/RMB大小写转换.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class RenMingBi {
}
```

-----
---

- 邮箱 :[email protected]
- Good Luck!
19 changes: 19 additions & 0 deletions Android基础知识/SDK无法更新配置.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
SDK无法更新配置
===

1.`SDK Manager下Tools->Options`勾选`Force https://… sources to be fetched using http://…`,强制使用`http`协议。
2. 修改`hosts`文件。`Windows``C:\WINDOWS\system32\drivers\etc`目录下,`Linux`用户打开`/etc/hosts`文件。打开文件后添加以下内容。
```
#Google主页
203.208.46.146 www.google.com
#这行是为了方便打开Android开发官网 现在好像不翻墙也可以打开
74.125.113.121 developer.android.com
#更新的内容从以下地址下载
203.208.46.146 dl.google.com
203.208.46.146 dl-ssl.google.com
```

---

- 邮箱 :[email protected]
- Good Luck!
9 changes: 9 additions & 0 deletions Android基础知识/VideoView源码分析.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
VideoView源码分析
===



---

- 邮箱 :[email protected]
- Good Luck!

0 comments on commit c476919

Please sign in to comment.