Android 学习笔记②
来源:互联网 发布:java使用redis做缓存 编辑:程序博客网 时间:2024/04/30 02:44
21.得到一个布局的方法
private LayoutInflater inflater; inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
或者:
LayoutInflaer.from(this).inflate(R.layout.xmlName, null);
或者:
getLayoutInflater(this).inflate(R.layout.xmlName, null);
22:通知Notification
defalut 属性: DEFAULT_ALL 使用所有默认值,包括声音,震动,闪光灯
DEFAULT_LIGHT 使用闪光灯
DEFAULT_SOUNDS 使用声音
DEFAULT_VIBRATE 使用振动
(注意在使用ALL 和ViBrate的时候,要给apk加入震动的权限 )
<uses-permission android:name = "android.permission.VIBRATE"/>
23.通过文件名得到对应的ID
getResources().getIdentifier("文件名", "drawable", getActivity().getApplication().getPackageName());//getActivity()碎片中使用//第一个参数:文件名//第二个参数:文件类型:drawable,layout//第三个参数:文件包名
24.得到SDCard的路径
Environment.getExternalStorageDirectory().toString();
25.得到一个目录下的文件列表(带过滤器)
File[] files= new File("文件路径").listFiles(new FileFilter() {@Overridepublic boolean accept(File pathname) {// TODO Auto-generated method stubreturn false;}});
26.把下载下来的模拟器安装到模拟器上
①进入到apk的文件夹
②adb install 名字.apk (可以使用Tab键自动填充名字)
27.自定义SeekBar,PrgoressBar等进度条的背景层等
<?xml version="1.0" encoding="utf-8"?><layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <!-- 背景层 --> <item android:id="@android:id/background" android:drawable="@drawable/seek_bg"/> <!-- 第二进度层 --> <item android:id="@android:id/secondaryProgress" android:drawable="@drawable/second_pro_bg"/> <!-- 第一进度层 --> <item android:id="@android:id/progress" android:drawable="@drawable/first_pro_bg"/></layer-list>
<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/seek_thumb_normal" android:state_pressed="false"/> <item android:drawable="@drawable/seek_thumb_pressed" android:state_pressed="true"/></selector>
<SeekBar android:id="@+id/m_seek" android:layout_width="match_parent" android:layout_height="wrap_content" android:progressDrawable="@drawable/seek_bar_drawable" android:thumb="@drawable/seek_thumb"/>
28.使用手机系统默认的软件打开音频,视频等
/* 播放录音文件 */private void playMusic(File file) {Intent intent = new Intent();intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);intent.setAction(android.content.Intent.ACTION_VIEW);/* 设置文件类型 */intent.setDataAndType(Uri.fromFile(file), "audio");startActivity(intent);}
29
Button或者ImageButton的背景设为透明或者半透明
半透明<Button android:background="#e0000000" ... />
透明<Button android:background="#00000000" ... />
30.时间View的监听
new TimePickerDialog(this, null, hourOfDay, minute, true).show();//其中null为选择器的监听,true表示是24小时制
31.广播
<application android:allowBackup="true" android:icon="@drawable/app_icon" android:label="@string/app_name" android:theme="@android:style/Theme.Light.NoTitleBar" > <activity android:name="com.siyehuazhilian.musicplay.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="audio/*" /> </intent-filter> </activity> </application>
一个app有许多个Activity,
一个Activity有许多个<intent-filter>
一个<intent-filter>有一个<action>,一个<category>,一个<data>
<action>表示你要执行的动作,常用的标准动作:
ACTION_MAIN,他的值我们比较熟悉:“android.intent.action.MAIN”这个值我们在每个AndroidManifest.xml文档中都可以看到。他标记当前Activity作为一个程序的入口。
ACTION_VIEW,将数据显示给用户。ACTION_VIEW通常和特定的data相配合使用,用于给用户显示数据。
ACTION_DIAL,用于描述给用户打电话的动作,通过和data配合使用将会触发给特定的data的用户达电话。
ACTION_PICK,从特定的一组数据中进行选择数据操作。
ACTION_EDIT,编辑特定的数据。
ACTION_DELETE,删除特定的数据。
<category>
android.intent.category.LAUNCHER表示用快捷方式启动
android.intent.category.DEFAULT表示用默认方式启动,比如说我们打开.doc后缀的格式文件,就会默认用Word打开,如果设置了用WPS.怎默认用WPS.如果没有设置,则选择让用户自己选择一个打开
android.intent.category.HOME表示在桌面打开
<data>表示能容纳的类型
audio/*表示所有的音频
mepg/*表示视频等等
32.使用Intent调用浏览器,电话,短信等
Uri uri = Uri.parse("http://www.baidu.com");Intent intent = new Intent(Intent.ACTION_VIEW, uri);startActivity(intent);
33.截屏
View view = getWindow().getDecorView();view.setDrawingCacheEnabled(true);view.buildDrawingCache();Bitmap b1 = view.getDrawingCache();Bitmap bitmap = Bitmap.createBitmap(b1, 0, 0, b1.getWidth(),b1.getHeight());view.destroyDrawingCache();
34,发送图片,彩信,分享的微信朋友圈,QQ说说,新浪微博等
Uri mUri = Uri.parse(("file://"+ Environment.getExternalStorageDirectory() + "/"+ currentDay + ".png"));Intent intent = new Intent(Intent.ACTION_SEND);intent.putExtra(Intent.EXTRA_STREAM, mUri);intent.setType("image/png");startActivity(intent);
35.Message发送一个对象
// Message msg = new Message();// msg.what = MSG_UPDATE;// msg.obj = newPro;// mHandler.sendMessage(msg);Message msg = mHandler.obtainMessage(MSG_UPDATE, newPro);msg.sendToTarget();
36,GridView宽度不够铺满整个屏幕,可以使用一下方法
android:stretchMode = "columnWidth"
37.设置ImageView的缩放方式,可以平铺.拉伸,适应等
android:scaleType = "方式"
38.如果一个ImageView始终无法铺满整个屏幕,可以尝试一下方法
android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin"
①看看父控件是否包含这个,如果有,可以删除
②设置图片的缩放方式,因为有可能你的图片比例和屏幕的比例不一样
39
android字体加粗
一、英文字体加粗
在xml文件中使用android:textStyle="bold"
二、中字体加粗
不能通过xml文件将中文设置成粗体,将中文设置成粗体的方法是:
TextView tv = (TextView)findViewById(R.id.TextView01);
TextPaint tp = tv.getPaint();
tp.setFakeBoldText(true);
40.Intent传递对象,可以通过Bundle来传递
Intent intent = new Intent(this,BookView.class); Book book = new Book(); book.setName("manmonth"); book.setTime("1975"); book.setAuthor("Brooks"); Bundle bundle = new Bundle(); bundle.putParcelable("book", book); intent.putExtras(bundle); startActivity(intent);
- Android 学习笔记②
- Android学习笔记--Gson笔记
- Android学习笔记
- Android学习笔记(二)
- android学习笔记--序
- android学习笔记1
- android学习笔记2
- android学习零碎笔记
- Android 学习笔记
- Android学习笔记(一)
- Android ExpandableListActivity 学习笔记
- Android EditText 学习笔记
- Android学习笔记3
- Android学习笔记4
- Android学习笔记5
- Android学习笔记9
- Android Animation学习笔记
- Android 学习笔记
- 敏捷的商业价值是什么,与传统对比的特点是什么?
- windows模拟键盘输入,QT实现虚拟键盘的实现方式
- Codeforces Round #215 (diy.2) C. Sereja and Algorithm
- android客户端与servlet服务器交互简单示例
- 泛型
- Android 学习笔记②
- 如何安装开发环境
- OSPF inter-area routing (1)
- 互联网创业如何收集用户反馈?
- The import java.util cannot be resolved
- 用一个易拉罐将家里的WiFi信号增强一倍
- mySQL 命令
- 在RHEL 6.4 x86_64平台上把编译器从gcc-4.4.7-3.el6.x86_64升级到最新版的编译器gcc-4.8.2
- select()函数以及FD_ZERO、FD_SET、FD_CLR、FD_ISSET