Android一些常用知识和代码(不断更新) 1.如何调用外部图片选择器,选择图片并返回结果
// 获取照片
Intentin = new Intent(Intent.ACTION_GET_CONTENT);
in.setType(
" image/* " );
startActivityForResult(in,
0 ); 然后Activity中还要加上一个结果返回接收
@Override
protected void onActivityResult( int requestCode, int resultCode,
Intentintent)
{
super .onActivityResult(requestCode,resultCode,intent);

System.out.println(intent.getDataString());
ImageViewview
= new ImageView( this );
view.setImageURI(intent.getData());
((LinearLayout)findViewById(R.id.layout)).addView(view);

System.out.println(requestCode);
}

2.如何调用Google Web Search?
其实android提供了一个很方便的调用方式,就是用Intent去调用系统的Activity,代码如下:
// 搜索
Intentsearch = new Intent(Intent.ACTION_WEB_SEARCH);
search.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
search.putExtra(SearchManager.QUERY,
" tigertian " );
final BundleappData = getIntent().getBundleExtra(SearchManager.APP_DATA);
if (appData != null ){
search.putExtra(SearchManager.APP_DATA,appData);
}

startActivity(search);
执行这段代码之后,就会跳转到google的网站并自动搜索与tigertian相关的记录

3.为什么WebView在进行loadUrl的时候,有时候会弹出Android的自带浏览器进行浏览?
被访问页面如果不带跳转(Redirect)是不会弹出自带浏览器的。但如果带跳转(Redirect)的话WebView是做不到的,所以他会调用相应的浏览器进行跳转访问。

4.有按钮的列表项为可以点击吗?
可以,但是需要将按钮的Focusable属性置为false,Checkbox等控件同理。

5.android:layout_weight何时有效果?
<AutoCompleteTextView android:layout_height="wrap_content" android:layout_weight="2"
android:layout_width="wrap_content" android:completionThreshold="1"
android:id="@+id/AutoCompleteSearchGame"></AutoCompleteTextView>
当layout_height和layout_width都未wrap_content的时候有效果。

6、如果调用浏览器?
使用startActivity传递这个intent就可以调用浏览器了new Intent(Intent.ACTION_VIEW, Uri.parse(url))

---------------------------------------------------------
专注移动开发
Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian

更多相关文章

  1. 使用Git下载Google Android源代码
  2. android 单选(RadioGroup )复选(CheckBox)按钮的应用
  3. Android中用代码设置ImageView的src和background
  4. Android 标题栏添加返回按钮及响应
  5. Android 退出提示框 代码
  6. 我的Android进阶之旅------>android api的源代码下载地址
  7. 简单几段代码实现窗口抖动
  8. android之按钮单击事件及监听器的实现方式

随机推荐

  1. Google Android's Gingerbread Update Co
  2. setting proxy for Android(安卓)SDK Man
  3. Android采用SAX解析XML文档
  4. Android(安卓)actrivityrealut
  5. Android(安卓)Studio编译失败问题(aapt2)
  6. android 程序漰溃 后台handle处理类
  7. android:parentActivityName
  8. gridView在scrollview中显示不全的问题
  9. android 中Spinner与dialog的综合应用
  10. android中layout_weight的理解