Android开发问题总结(一)

这是日常工作中遇到的问题,汇总下来以备日后查看

1、字体修改: as下assets文件加的创建,修改文字的字体,目前只支持ttf格式

setTypeFace(tv_luckydraw_rule, "fonts/LanTingZhongCuHei.TTF");
/**
* 设置字体
*
* @param mTextView
* @param font
*/
private void setTypeFace(TextView mTextView, String font) {
Typeface typeFace = Typeface.createFromAsset(getAssets(), font);
mTextView.setTypeface(typeFace);
}

2、让ExpandableListView的group取消点击监听

listview..setOnGroupClickListener(this);
/**
* 取消group的点击监听
*/
@Override
public boolean onGroupClick(ExpandableListView expandableListView, View view, int i, long l) {
return true;
}

3、EditText降输入的小写字母自动,变化为大写字母(注:设置完之后只能输入大写字母)

import android.text.method.ReplacementTransformationMethod;

/**
* @author bruce.z
* 
*/
public class AllCapTransformationMethod extends ReplacementTransformationMethod {

@Override
protected char[] getOriginal() {
    char[] aa = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j','k','l','m','n','o','p','q','r','s','t','u','v',    'w','x','y','z' };
    return aa;
}

@Override
protected char[] getReplacement() {
    char[] cc = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J','K','L','M','N','O','P','Q','R','S','T','U','V',    'W','X','Y','Z' };
    return cc;
}

}
	
editext.setTransformationMethod(new AllCapTransformationMethod ());

4、TimePickerDialog,选择0-9分钟时,显示为10:0 10:1,要改成 10:00 10:01 的解决方式

/**
* 设置时间选择器
*/
private void setTimePickerDialog() {
mCalendar = Calendar.getInstance();
mCalendar.setTimeInMillis(System.currentTimeMillis());
final int hour = mCalendar.get(Calendar.HOUR_OF_DAY);
int minute = mCalendar.get(Calendar.MINUTE);
new TimePickerDialog(this,new TimePickerDialog.OnTimeSetListener() {

@Override

public void onTimeSet(TimePicker view,int hourOfDay,int minute)
{

String sHour = hour < 10 ? "0" + hour : "" + hour;
String sMinutes = minute < 10 ? "0" + minute : ""
+ minute;
tv_flight_start_time.setText(sHour + ":" + sMinutes);
}

}, hour, minute, true).show();
}

5、editText设置软键盘删除键监听

editText.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View view, int i, KeyEvent keyEvent) {
                if (i == KeyEvent.KEYCODE_DEL
                        && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
                    editText.setText("");
                    return true;
                }
                return false;
            }

        });

6、应用商店有同名的APP,需要认领应用一致的签名写入空包中,签名写入空白apk

jarsigner-verbose -keystore D:\oldClient -signedjar D:\TestSign_OK.apk D:\TestSign.apkjsj

jarsigner -verbose -keystore [您的私钥存放路径]-signedjar [签名后文件存放路径][未签名的文件路径] [您的证书名称]

7、TextView过长隐藏部分文字,可指定开头,中部,结尾等

TextView中有个ellipsize属性,作用是当文字过长时,该控件该如何显示,解释如下:

1.android:ellipsize=”start”—–省略号显示在开头

2.android:ellipsize=”end”——省略号显示在结尾

3.android:ellipsize=”middle”—-省略号显示在中间

4.android:ellipsize=”marquee”–以跑马灯的方式显示(动画横向移动)

还需将文字设置成maxline=1,指定固定宽度

8、解决RecycleView中item中子View,setVisibility为GONE隐藏视图但是现实空白的方法

public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
    ...

    public void setVisibility(boolean isVisible){
        RecyclerView.LayoutParams param = (RecyclerView.LayoutParams)itemView.getLayoutParams();
        if (isVisible){
            param.height = LinearLayout.LayoutParams.WRAP_CONTENT;
            param.width = LinearLayout.LayoutParams.MATCH_PARENT;
            itemView.setVisibility(View.VISIBLE);
        }else{
            itemView.setVisibility(View.GONE);
            param.height = 0;
            param.width = 0;
        }
        itemView.setLayoutParams(param);
    }

    public ViewHolder(View itemView) {
        super(itemView);
        ...
    }
}
上一篇:c++重载运算符、友元函数


下一篇:格式化时间(xx天xx时xx分xx秒)