`
lxr215
  • 浏览: 58872 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论
文章列表
动态代理实现方法耗时统计:   网上查了些资料和看别人的例子, 自己写了个demo跑了下. 1.传统方法:    假设有1个类A, 有一个方法play(); 如果用传统的方法统计play()耗时, 一般会这样做: public static void main(String[] args) { A a = new A(); long start = System.currentTimeMillis(); a.play(); long end = System.currentTimeMillis(); ...
设置EditText显示或隐藏密码.     在CheckBox的onCheckedChanged()方法中, 判断是否选中. if (isChecked) { System.out.println("checked"); // 显示密码 password_edit.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); } else { System.out.println("not checked"); // 隐藏密码 ...
设置ImageView透明: ImageView.setBackgroundDrawable(drawable); ImageView.getBackground().setAlpha(100); 设置ImageView不透明: ImageView.setBackgroundDrawable(drawable); ImageView.getBackground().setAlpha(255); 如果有其他控件引用了这个drawable图片, 则透明时,其他控件也会透明. 应用mutate(); ImageView.setBackgroundDrawable(draw ...
动态输入日期和时间: DatePicker / TimePicker / DatePickerDialog / TimePickerDialog
AnalogClock / DigitalClock: 必须设置宽和高.
AutoCompleteTextView实现自动提示: setAdapter(T adapter);

Spinner

Spinner: 下拉菜单(相当于swing的combo box, heml的<select>) 自定义下拉菜单样式(setDropDownViewResource())

Dialogs

ProgressDialog: android.app.ProgressDialog; ProgressDialog dialog = ProgressDialog.show(MyActivity.this, "", "Loading. Please wait...", true); ProgressDialog必须在后台程序运行完毕前, 以dimmiss()方法来关闭取得焦点的对话框. AlertDialog: android.app.AlertDialog; fin ...

创建菜单

创建菜单: public boolean onCreateOptionsMenu(Menu menu) { menu.add(Menu.NONE, OPTION, Menu.NONE, R.string.menuoption); menu.add(Menu.NONE, OPTION, Menu.NONE, R.string.cancel); return super.onCreateOptionsMenu(menu); } public boolean onOptionsItemSelected(MenuItem item) { if(item.ge ...
android.graphics.Matrix缩放图片文件: int bmpWidth = bitmap.getWidth(); int bmpHeight = bitmap.getHeight(); // 要缩小的比例 0.8 float scale = 0.8; // 1.2 scaleWidth = scaleWidth * scale; // scaleWidth初始值为1.0f scaleHeight = scaleHeight * scale; // scaleHeight初始值为1.0f Matrix matrix = new Matri ...
控制不同文字字体Typeface:     1. 从外部字体文件构造 在assets下创建fonts文件夹,然后放入要使用的字体(.ttf), 然后 Typeface.createFromAsset(AssetManager mgr, String path); Typeface.createFromAsset(ContextWrapper.getAssets(), "fonts/MONACO.ttf"); 只支持.TTF格式字体, .FON,.TTC都不支持.   2. 使用android内置的Typeface Typeface.default ...
取得手机屏幕分辨率:   android.util.DisplayMetrics; DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int height = metrics.heightPixels; int width = metrics.widthPixels; 或者: Display display = getWindowManager().ge ...
自动判断字符并提供连接: 如输入电话,网址,email 方法1: TextView: android:autoLink="all/none/web/email/phone/map"     web: 以http://开头的     phone: 数字      android.text.util.Linkify     setAutoLinkMask (int mask);  设置后,点击时会调用相应的程序来执行, 如web浏览器,phone,email等   方法2: 使用android.text.util.Linkify; addLink ...
git获取Android源码: 1. git clone git://android.git.kernel.org/ + project path. 2. mkdir mydroid    cd mydroid   repo init -u git://android.git.kernel.org/platform/manifest.git   repo sync   git clone获取比较大的源码时, 不能断点续传, 比较恼火.   可以使用 git fetch 解决:      mkdir common cd common git init git fet ...

random使用练习

    博客分类:
  • Java
public class RandomTest { public static void main(String[] args) { for(int i=1; i<=100; i++) { System.out.print(randomInt(10,20) + "\t"); if(i%10==0) { System.out.println(); } } } public s ...
Global site tag (gtag.js) - Google Analytics