知识点

来源:互联网 发布:网络安全工程师学习 编辑:程序博客网 时间:2024/05/20 00:12

1、邮箱验证

//第一种:^(\w+((-\w+)|(\.\w+))*)\+\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$//第二种:^([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)*@([a-zA-Z0-9]*[-_]?[a-zA-Z0-9]+)+[\.][A-Za-z]{2,3}([\.][A-Za-z]{2})?$//第三种:^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$//第四种^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$//第五种^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$

2、设置Radiobutton时距按钮和文字间距太大

       是由于在代码中没有设置android:background="@null"

       完整设置为:

                 android:drawableLeft="@drawable/single_button_bg"                 android:button="@null"                 android:background="@null"

3、listview 取消头部和底部分割线

       

   listview分割线会在头部、数据item、及根部的底部打印,如果要取消头部分割线必须

   先设置期方法

    addHeaderView(headView, null, true);
     addFooterView(footView, null, true);

   注意:第三个参数必须为true,否则无效

 

   //显示头部出现分割线

   listview.setHeaderDividersEnabled(true);
    //禁止底部出现分割线 
    listview.setFooterDividersEnabled(false);


    android:headerDividersEnabled="true"

    android:footerDividersEnabled="false"


4、TextView 设置部分字体颜色


    
方法一:       SpannableStringBuilder fontStyleBuilder=new SpannableStringBuilder(textString);        fontStyleBuilder.setSpan(new ForegroundColorSpan(Color.RED), 0, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);        fontStyleBuilder.setSpan(new ForegroundColorSpan(Color.GREEN), 3, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);        fontStyleBuilder.setSpan(new ForegroundColorSpan(Color.BLUE), 5, 8, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);        textView.setText(fontStyleBuilder);方法二:       textView.setText(Html.fromHtml("测试<font color=red >文字</font>"));


5、java.lang.illegalargumentexception:can not perform this action after onSaveInstance at

 

今天使用Fragment的时候,出现了这个错误 IllegalStateException: Can not perform this action after onSaveInstanceState:

[java] view plain copy
print?
  1. E/AndroidRuntime(12747): Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState  
  2.     at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:1314)  
  3.     at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:1325)  

是在使用FragmentTransition的 commit方法添加一个Fragment的时候出现的,后来在官网找到了相关的

说明:http://developer.android.com/reference/android/app/FragmentTransaction.html#commitAllowingStateLoss()

public abstract int commitAllowingStateLoss ()                                    Added in API level 11

Like commit() but allows the commit to be executed after an activity's state is saved. This is dangerous 

because the commit can be lost if the activity needs to later be restored from its state, so this should 

only be used for cases where it is okay for the UI state to change unexpectedly on the user.

大致意思是说我使用的 commit方法是在Activity的onSaveInstanceState()之后调用的,这样会出错,因为onSaveInstanceState

方法是在该Activity即将被销毁前调用,来保存Activity数据的,如果在保存玩状态后再给它添加Fragment就会出错。解决办法就

是把commit()方法替换成 commitAllowingStateLoss()就行了,其效果是一样的。


6、修改eclipse文件默认打开方式

       最近项目中遇到的问题:在eclipse中打开图片都是乱码

       解决方案:1、打开电脑点击任意图片,修改默认打开方式为照片查看器

                           2、window->Preferences->Gerneral->Editors->File Associations


7、默认提示

      android:completionThreshold=”1″

     属性设置了一个阀值,规定用户打了多少字符之后才出现自动提示,默认值是2,我们在这里改成了1。


8、修改背景透明度,引发其他布局文件也变为透明(getBackground().setAlpha所导致问题

       描述:两个textview,background都指向相同的资源,那如果text1.getBackground().setAlpha(255)(不透明),那text2的背景是不是也跟着变成不透明的呢,答案是yes,那为什么呢:默认情况下,所有的从同一资源(R.drawable.***等等)加载的实例都共享一个共用的状态,如果你更改一个实例的状态,其余的实例都会接收到相同的通知。

     解决方法:text1.getBackground().mutate().setAlpha(255);

       
/** * Make this drawable mutable. This operation cannot be reversed. A mutable * drawable is guaranteed to not share its state with any other drawable. * This is especially useful when you need to modify properties of drawables * loaded from resources. By default, all drawables instances loaded from * the same resource share a common state; if you modify the state of one * instance, all the other instances will receive the same modification. * * Calling this method on a mutable Drawable will have no effect. * * @return This drawable. * @see ConstantState * @see #getConstantState() */public Drawable mutate() {    return this;}

9、在java代码中设置图标

       private  Drawable drawableLocation;

       private Textview etInputStart;

        drawableLocation = getResources().getDrawable(R.drawable.transfer_icon_location);

       drawableLocation.setBounds(0, 0, drawableLocation.getMinimumWidth(), drawableLocation.getMinimumHeight());//在文本的左边设置图标

       etInputStart.setCompoundDrawables(drawableLocation,  null, null, null);

10、windowSoftInputMode属性

       

各值的含义:

  【A】stateUnspecified:软键盘的状态并没有指定,系统将选择一个合适的状态或依赖于主题的设置

  【B】stateUnchanged:当这个activity出现时,软键盘将一直保持在上一个activity里的状态,无论是隐藏还是显示

  【C】stateHidden:用户选择activity时,软键盘总是被隐藏

  【D】stateAlwaysHidden:当该Activity主窗口获取焦点时,软键盘也总是被隐藏的

  【E】stateVisible:软键盘通常是可见的

  【F】stateAlwaysVisible:用户选择activity时,软键盘总是显示的状态

  【G】adjustUnspecified:默认设置,通常由系统自行决定是隐藏还是显示

  【H】adjustResize:该Activity总是调整屏幕的大小以便留出软键盘的空间

  【I】adjustPan:当前窗口的内容将自动移动以便当前焦点从不被键盘覆盖和用户能总是看到输入内容的部分

0 0
原创粉丝点击