1.Edittext输入为密码有两种方法,分别是:
Android:inputType="textPassword"
android:password="true"
2.Android中gravity与layout_gravity的区别
LinearLayout有两个非常相似的属性:android:gravity与android:layout_gravity。他们的区别在于:android:gravity用于设置View组件的对齐方式,而android:layout_gravity用于设置Container组件的对齐方式。
举个例子,我们可以通过设置android:gravity="center"来让EditText中的文字在EditText组件中居中显示;同时我们设置EditText的android:layout_gravity="right"来让EditText组件在LinearLayout中居中显示
3. android 2.2版使用getFromLocation不能解析地址(错误:Service not Available);
4.部分真机getFromLocation()/getFromLocationName()返回0个解析值。
这是因为该真机版本不支持backend servic;下面是google原话
[xhtml] view plaincopyprint?
The Geocoder class requires a backend service that is not included in the core android framework. The Geocoder query methods will return an empty list if there no backend service in the platform. Use the isPresent() method to determine whether a Geocoder implementation exists.
5.旋转动画(旋转后停在旋转后的位置)
RotateAnimation rotateAnimation = new RotateAnimation(from, to,
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setInterpolator(new LinearInterpolator());
rotateAnimation.setDuration(ANIMATION_DURATION);
rotateAnimation.setFillAfter(true);


imageView.startAnimation(rotateAnimation);


1.android自定义日期时间对话框,在手工输入日期数字后,点击保存获取日期对话框的值,发现所获取的值是我们输入前的那个值。
解决办法:在获取事件中,获取日期之前,执行下日期对话框对象的clearFocus()即可。如:datePicker.clearFocus();
2.在HorizontalScrollView中,虽然我已经设了其子节点内容的宽度是fill_parent。但当内容较少时,其子节点还是根据内容自适应宽度,不能满屏。出现右边一块空白。
解决办法:设置HorizontalScrollView的android:fillViewport="true"。也就是设置是否将HorizontalScrollView的内容宽度拉伸以适应视口(viewport)
3.模拟器模拟sdcard插入或者拔出
先执行adb shell,进入模拟器的终端,然后输入sdutil mount /sdcard 或者 sdutil unmount /sdcard
4.使用webview,在用JS调java方法时,2.3.3和2.2.2版会使应用程序直接崩溃,据网上说是android这两个版本本省的bug,但是我发现一个解决方案:
在需要用js调用Java,我们可以通过console.log("你要传的值");
在java端,先声明一个WebChromeClient,复写回调函数onConsoleMessage(String message, int lineNumber, String sourceID),其中message就是你传过来的值。这样你就可以该干嘛干嘛,想干嘛干嘛。
测试2.1以上的版本都通过。
5.android xml 字符串中的空格:  (代表空格)
6.点击LinearLayout使用selector改变TextView字体颜色
在父控件中添加android:clickable=“true” android:focusable=“true”,而在子控件中添加android:duplicateParentState=“true”子控件就能获得父控件的点击事件
7.怎么在release版下不输出日志?
方法一:如果有做代码混淆,在配置文件中加入下面语句
-assumenosideeffects class android.util.Log {
public static *** d(...);
public static *** v(...);
public static *** i(...);
}
方法二:对于没做代码混淆的,可以按照下面方法:
在manifest文件中加入android:debuggable="@bool/build_log"
<application
android:name="MyApplication"
android:icon="@drawable/gift"
android:label="@string/app_name" android:debuggable="@bool/build_log">
定义一个日志类
public class Lol {


public static final boolean ENABLE_LOG = true & MyApplication.sDebug;


private static final boolean DEBUG = true & ENABLE_LOG;


private static final boolean VERBOSE = true & ENABLE_LOG;


private static final boolean TEMP = true & ENABLE_LOG;


private static final boolean WARNING = true & ENABLE_LOG;


private static final boolean INFO = true & ENABLE_LOG;


private static final boolean ERROR = true & ENABLE_LOG;


public static void obvious(String tag, String msg) {
if (DEBUG) {
msg = "*********************************\n" + msg
+ "\n*********************************";
Log.d(tag, msg);
}
}


public static void d(String tag, String msg) {
if (DEBUG)
Log.d(tag, msg);
}


public static void d(boolean bool, String tag, String msg) {
if (TEMP&bool)
Log.d(tag, msg);
}


public static void i(String tag, String msg) {
if (INFO)
Log.i(tag, msg);
}


public static void e(String tag, String msg) {
if (ERROR)
Log.e(tag, msg);
}


public static void e(boolean bool, String tag, String msg) {
if (TEMP&bool)
Log.e(tag, msg);
}


public static void v(String tag, String msg) {
if (VERBOSE)
Log.v(tag, msg);
}


public static void w(String tag, String msg) {
if (WARNING)
Log.w(tag, msg);
}


public static String getStackTraceString(Exception e) {
return Log.getStackTraceString(e);
}


public static void w(String tag, String msg, Exception e) {
if (WARNING)
Log.w(tag, msg,e);
}
}
8.android使用include标签出现nullpointer异常
在使用inlcude时,在inluce在include便签中不能带ID,如果带了ID需要用inflate加载要被inlude的这个布局文件,然后再获取这个布局文件上的对象。
我在使用的过程中发现,include标签如果带了ID,那么他包含的布局文件的根节点就不要包含ID,否则出现nullpointer异常。
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
android:orientation="vertical" >
<!-- 动态显示界面 -->


<LinearLayout
android:id="@+id/body"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/white"
android:orientation="vertical" >
</LinearLayout>
<!-- 底部功能菜单栏 -->


<include
layout="@layout/tab_menu_view" />


</LinearLayout>


tab_menu_view.xml
<?xml version="1.0" encoding="UTF-8"?>
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/radiogroupMenu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >


<RadioButton
android:id="@+id/radiobtnHome"
style="@style/main_tab_bottom"
android:checked="true"
android:drawableTop="@drawable/menu_home"
android:gravity="center"
android:text="定位" />


<RadioButton
android:id="@+id/radiobtnTrack"
style="@style/main_tab_bottom"
android:drawableTop="@drawable/menu_tracker"
android:gravity="center"
android:text="追踪" />


<RadioButton
android:id="@+id/radiobtnHelp"
style="@style/main_tab_bottom"
android:drawableTop="@drawable/menu_help"
android:gravity="center"
android:text="求助" />


<RadioButton
android:id="@+id/radiobtnSecurity"
style="@style/main_tab_bottom"
android:drawableTop="@drawable/menu_mobilesafe"
android:gravity="center"
android:text="防盗" />


<RadioButton
android:id="@+id/radiobtnMore"
style="@style/main_tab_bottom"
android:drawableTop="@drawable/menu_more"
android:gravity="center"
android:text="更多" />


</RadioGroup>


8.ScrollView中的组件设置android:layout_height="fill_parent"不起作用的解决办法
在ScrollView中添加一个android:fillViewport="true"属性就可以了。顾名思义,这个属性允许ScrollView中的组件去充满它。
9.动态添加子view的时候,子view的设置了背景但是却没有填充整个子view.解决办法:
在添加时候,设置添加的子view的填充方式
LinearLayout.LayoutParams params =new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
mBodyView.addView(getLocalActivityManager().startActivity(target, intent).getDecorView(),params);
10.自己写的应用总是导致launcher重启。原因是在设置全局皮肤的时候加了<item name="android:windowIsTranslucent">true</item>。
然后再将对应的activity设置为横屏或者竖屏,再加上android:configChanges="keyboardHidden|orientation",让横竖屏转换时不执行oncreate即可。


11.获取当前设备的像素,密度
DisplayMetrics metric = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metric);
int width = metric.widthPixels; // 屏幕宽度(像素)
int height = metric.heightPixels; // 屏幕高度(像素)
float density = metric.density; // 屏幕密度(0.75 / 1.0 / 1.5)
int densityDpi = metric.densityDpi; // 屏幕密度DPI(120 / 160 / 240)
Log.i(tag, width + "," + height + "," + density + "," + densityDpi);




12.当listview的item上面有checkbox控件时,你设置listview的item点击时更换背景不起作用。
解决办法:设置checkbox的 android:clickable="false"
android:focusable="false"


13.android EditText设置输入负小数:android:inputType="numberDecimal|numberSigned".

更多相关文章

  1. Android(安卓)Tips---Android平台常见属性集合
  2. LinearLayout和RelativeLayout 属性对比
  3. Android设置透明、半透明等效果
  4. android 布局padding和margin的区别
  5. Android(安卓)layout布局属性、标签属性总结大全
  6. Android(安卓)之 ProgressBar用法介绍
  7. Android(安卓)设置背景透明
  8. android中searchable的使用
  9. Android日历控件

随机推荐

  1. android EditText和输入法相关知识总结
  2. Android(安卓)判断是否有声音在播放
  3. android中部分Intent用法实例
  4. 13-4-1 Android中list和Adapter的使用
  5. android 的系统编译
  6. qt部署到android设备,很久没响应解决办法
  7. Android(安卓)获取路径目录方法
  8. ImageView的属性
  9. Android正在启动的提示框
  10. build.gradle文件介绍,gradle版本对应