android开发 日常常用整理(待续)

1、全屏:requestWindowFeature(Window.FEATURE_NO_TITLE);

2、竖屏:setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);// 竖屏

3、/mnt/sdcard/:Environment.getExternalStorageState()

4、隐藏键盘:

1)、getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

2)、((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE))
.hideSoftInputFromWindow(GaodeSearchActivity.this
.getCurrentFocus().getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);

5、自定义布局背景:android:background="@drawable/shape"

    shape.xml:
    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <!--布局背景色-->
        <solid android:color="#ffffcc" />
        <!--布局边角弧度-->
        <corners android:radius="8px" />
        <!--布局边框颜色及宽度-->
        <stroke android:color="#32CD32" android:width="0px" />

    </shape> 

6、linux下安装apk:

./adb push xx.apk  /data/app

7、android设备上卸载apk

     a、自定义卸载

              public void uninstallApp(Context context, String appPackage)
                 {
                     Uri packageURI = Uri.parse("package:" + appPackage);
                     Intent uninstallIntent = new Intent(Intent.ACTION_DELETE,packageURI);
                     context.startActivity(uninstallIntent);
                 }

     b、调用系统卸载程序进行卸载

              public void uninstallApp(Context context, String appPackage)
                 {
                     Uri packageURI = Uri.parse("package:" + appPackage);
                     Intent uninstallIntent = new Intent(
                             Settings.ACTION_APPLICATION_DETAILS_SETTINGS, packageURI);
                     context.startActivity(uninstallIntent);
                 }


8、liunx下安装chm阅读器: sudo apt-get install chmsee


9、 设置字体
    风格:

public void setTypeFace(TextView view) {
        AssetManager mgr = getAssets();
        Typeface tf = Typeface.createFromAsset(mgr, "fonts/STXINGKA.TTF");// 根据路径得到Typeface,STXINGKA.TTF为assets/fonts下的字体包
        view.setTypeface(tf);// 设置字体
    }

大小:

setTextSize(TypedValue.COMPLEX_UNIT_PX,20); //20像素
setTextSize(TypedValue.COMPLEX_UNIT_SP,20); //22SP
setTextSize(TypedValue.COMPLEX_UNIT_DIP,20);//22DIP
下划线:
方法a、 <string name="value"><u>value</u></string>
方法b、textview.setText(Html.fromHtml("<u>"+"value"+"</u>"));
方法c、textview.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);

10、显示html文本

String value = "&lt;p style=&quot;text-indent;:2em;&quot;&gt;你好&lt;/p&gt;";
Spanned spanned = Html.fromHtml(value);
textview.setText(Html.fromHtml(spanned.toString()));

11、把一个view转化成bitmap对象

public static Bitmap getViewBitmap(View view)
{
view.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
view.layout(0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
view.buildDrawingCache();
Bitmap bitmap = view.getDrawingCache();
return bitmap;
}

12、scrollview嵌套listview或gridview

重写girdview及listview的

@Override
 public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
 {
  int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,
    MeasureSpec.AT_MOST);
  super.onMeasure(widthMeasureSpec, expandSpec);
 }

13、打电话

/**
* 调用系统打电话界面

* @param telnum
*/
public static void dialWithView(Activity activity, String telnum)
{
Intent intent = new Intent();
// 系统默认的action,用来打开默认的电话界面
intent.setAction(Intent.ACTION_DIAL);
// 需要拨打的号码
intent.setData(Uri.parse("tel:" + telnum));
activity.startActivity(intent);
}


/**
* 不调用打电话界面,直接拨打
*/
public static void dialWithoutView(Activity activity, String telnum)
{
Intent phoneIntent = new Intent("android.intent.action.CALL",
Uri.parse("tel:" + telnum));
activity.startActivity(phoneIntent);
}

14、文字转码

/**
* 转码UTF-8格式字符串

* @param urlStr
* @return
*/
@SuppressWarnings("deprecation")
public static String decodeURL(String urlStr)
{
String returnStr = "";
try
{
urlStr = Html.fromHtml(urlStr).toString();
urlStr = Html.fromHtml(urlStr).toString();
String temp = URLEncoder.encode("%");
urlStr = urlStr.replaceAll("%", temp);
returnStr = URLDecoder.decode(urlStr, "UTF-8");
} catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}


return returnStr;
}


public static String decode(String urlStr)
{
String returnStr = "";
try
{
returnStr = URLDecoder.decode(urlStr, "UTF-8");
} catch (UnsupportedEncodingException e)
{
e.printStackTrace();
}


return returnStr;
}

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值