Android日常使用记录

Android日常应用记录1、获取wifi的ip地址?WifiManager wifiManager (WifiManager) getSystemService(WIFI

Android日常应用记录

1、获取wifi的ip地址

?

WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);   WifiInfo wifiInfo = wifiManager.getConnectionInfo();   int ipAddress = wifiInfo.getIpAddress();String ipAddressStr = Utils.intToIp(ipAddress); public static String convertIpaddr2String(int ipaddr)  {byte[] bytes = convertInt2Bytes(ipaddr);InetAddress addr = null;try {addr = InetAddress.getByAddress(bytes);} catch (UnknownHostException e) {e.printStackTrace();return null;}return addr.getHostAddress();}

?

2、?把图片变成圆角

         * 把图片变成圆角          * @param bitmap 需要修改的图片          * @param pixels 圆角的弧度          * @return 圆角图片          */          public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {                    Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Config.ARGB_8888);              Canvas canvas = new Canvas(output);                    final int color = 0xff424242;              final Paint paint = new Paint();              final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());              final RectF rectF = new RectF(rect);              final float roundPx = pixels;                    paint.setAntiAlias(true);              canvas.drawARGB(0, 0, 0, 0);              paint.setColor(color);              canvas.drawRoundRect(rectF, roundPx, roundPx, paint);                    paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));              canvas.drawBitmap(bitmap, rect, rect, paint);                    return output;          }  

?

3、Android边框圆角

?

<?xml version="1.0" encoding="utf-8"?>  <shape xmlns:android="http://schemas.android.com/apk/res/android">        <solid android:color="#000000" />        <corners android:topLeftRadius="10dp"                       android:topRightRadius="10dp"                    android:bottomRightRadius="10dp"                   android:bottomLeftRadius="10dp"/>    </shape>  
?

解释:solid的表示填充颜色,为了简单,这里用的是黑色。?
而corners则是表示圆角,注意的是这里bottomRightRadius是左下角而不是右下角,bottomLeftRadius右下角。?
当然上面的效果也可以像下面一样设置,如下:?<corners?android:radius="@drawable/corners_bg"??

?

?

?

?

?

?

?

?