1. 横屏的一种简单方法 只能横屏不能竖屏
<activity android:name=".SomeActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">

2.SaveInstanceState的使用
@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
// Save UI state changes to the savedInstanceState.
// This bundle will be passed to onCreate if the process is
// killed and restarted.
savedInstanceState.putBoolean("MyBoolean", true);
savedInstanceState.putDouble("myDouble", 1.9);
savedInstanceState.putInt("MyInt", 1);
savedInstanceState.putString("MyString", "Welcome back to Android");
// etc.
super.onSaveInstanceState(savedInstanceState);
}

@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
// Restore UI state from the savedInstanceState.
// This bundle has also been passed to onCreate.
boolean myBoolean = savedInstanceState.getBoolean("MyBoolean");
double myDouble = savedInstanceState.getDouble("myDouble");
int myInt = savedInstanceState.getInt("MyInt");
String myString = savedInstanceState.getString("MyString");
}

3.让editText不能用
editText.setFocusable(false);和editText.setEnabled(false);
只能使背景不同但是还是能输入进去能去,下面的办法是:
editText.setFilters(new InputFilter[] {
new InputFilter() {
public CharSequence filter(CharSequence src, int start, int end, Spanned dst, int dstart, int dend) {
return src.length() < 1 ? dst.subSequence(dstart, dend) : "";
}
}
});

4.连接网络下载图片简单代码:不要忘记放在线程里面或者AsyncTask 里面执行
http://developer.android.com/reference/android/os/AsyncTask.html:
private Bitmap fetchImage( String urlstr ){
try {
URL url;
url = new URL( urlstr );
HttpURLConnection c = ( HttpURLConnection ) url.openConnection();
c.setDoInput( true );
c.connect();
InputStream is = c.getInputStream();
Bitmap img;
img = BitmapFactory.decodeStream( is );
return img; }
catch ( MalformedURLException e ) {
Log.d( "RemoteImageHandler", "fetchImage passed invalid URL: " + urlstr );
}
catch ( IOException e ) {
Log.d( "RemoteImageHandler", "fetchImage IO exception: " + e );
}
return null;
}
5. 可以用来远端更新安装程序部分代码:
DexFile df = new DexFile(new File("/data/app/my_downloaded_lib.apk"));
ClassLoader cl = getClassLoader();
Class clazz = df.loadClass("com/my/lib/MyClass", cl);

6.调用选择时间加减的方框 注意不是timepiker :
<com.android.internal.widget.NumberPicker android:id="@+id/picker" android:layout_width="wrap_content" android:layout_height="wrap_content"/>

Object o = findViewById(R.id.picker);
Class c = o.getClass();
try {
Method m = c.getMethod("setRange", int.class, int.class);
m.invoke(o, 0, 9);}
catch (Exception e) {
Log.e("", e.getMessage());
}
http://groups.google.com/group/android-developers/browse_frm/thread/65da9820998fddc9/6151cc9800e6a04d?pli=1

7.对话框修改 标题栏的大小
dialog = new Dialog(context);
Window window = dialog.getWindow();
window.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
dialog.setContentView(R.layout.my_dialog_layout);
window.setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_custom_header);

8.程序更改Android Tab Icons
tabHost.setOnTabChangedListener(new OnTabChangeListener() {
public void onTabChanged(String tabId) {
if (TAB_MAP.equals(tabId)) {
ImageView iv = (ImageView)tabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.icon);
iv.setImageDrawable(getResources().getDrawable(R.drawable.tab_map_black));
iv = (ImageView)tabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.icon);
iv.setImageDrawable(getResources().getDrawable(R.drawable.tab_list_white));
}
else if (TAB_LIST.equals(tabId)) {
ImageView iv = (ImageView)tabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.icon);
iv.setImageDrawable(getResources().getDrawable(R.drawable.tab_map_white));
iv = (ImageView)tabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.icon);
iv.setImageDrawable(getResources().getDrawable(R.drawable.tab_list_black));
}
}
});

更多相关文章

  1. android panellistview 圆角实现代码
  2. Android如何在java代码中设置margin
  3. Android Content Provider详解及示例代码
  4. android中eclipse查看源代码
  5. Android开发之android_apk 在线安装(源代码分享)
  6. vlc android 代码编译
  7. 关于Android多项目依赖在Eclipse中无法关联源代码的问题解决 (an
  8. Android 7.1 触摸事件代码跟踪
  9. android 开发中将十六进制 颜色代码 转换为int类型数值 方法 :

随机推荐

  1. Android来电拦截的实现方法
  2. Android 生成图标的有力工具 Android Ass
  3. android 读取根目录下的文件或文件夹
  4. Android在启动adb时失败解决方案
  5. 【Android】获取控件的宽和高
  6. [置顶] 找到一个在Android上创建阻塞式模
  7. Android横竖屏的写法、及savedInstanceSt
  8. HTML5 Cache, Android(安卓)WebView
  9. 极光推送集成
  10. android c 如何规避Wunused-parameter等