1.自定义广播 接受网络状态
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mobNetInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
NetworkInfo wifiNetInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (!mobNetInfo.isConnected() && !wifiNetInfo.isConnected()) {
Toast.makeText(context, "检测到当前并未连接网络......",Toast.LENGTH_SHORT).show();
} else if (wifiNetInfo.isConnected()) {
Toast.makeText(context, "正在使用wifi连接,请放心使用......", Toast.LENGTH_SHORT).show();
} else if (mobNetInfo.isConnected()) {
Toast.makeText(context, "检测到正在使用移动网络,可能会消耗很多流量,建议在wifi下浏览.....", Toast.LENGTH_SHORT).show();
}
}
}
public class FontsType {
//字体的
static String 行楷 = "fonts/xingkai.ttf";
static String 宋楷 = "fonts/songti.ttf";
static String 鱼楷 = "fonts/yuti.ttf";
static String 楷体 = "fonts/kaiti.ttf";
public static Typeface type(AssetManager assets, String path) {
if (path.equals(行楷)) {
Typeface typeface1 = Typeface.createFromAsset(assets, 行楷);
return typeface1;
}
if (path.equals(宋楷)) {
Typeface typeface1 = Typeface.createFromAsset(assets, 宋楷);
return typeface1;
}
if (path.equals(鱼楷)) {
Typeface typeface1 = Typeface.createFromAsset(assets, 鱼楷);
return typeface1;
}else {
Typeface typeface1 = Typeface.createFromAsset(assets, 楷体);
return typeface1;
}
}
//字体的大小
public static float fontScale(Context context, float scale) {
DisplayMetrics dm = new DisplayMetrics();
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
windowManager.getDefaultDisplay().getMetrics(dm);
int screenHeight = dm.heightPixels;
float rate = (scale * (float) screenHeight / 1280);
Log.e("------>", "==rate==" + rate);
return rate;
}
3.webView字体大小
public class ZiTiScale {
public static void zitiStyle(final Context context, WebView webView) {
final WebSettings settings = webView.getSettings();
final SharedPreferences sharedPreferences = context.getSharedPreferences("hgz", Context.MODE_APPEND);
final SharedPreferences.Editor edit = sharedPreferences.edit();
String string = sharedPreferences.getString("teda1", null);
if (string == null) {
LogUtils.e("------------>", "==string==" + string);
LogUtils.e("------------>", "默认的字体为小号");
settings.setSupportZoom(true);
settings.setBuiltInZoomControls(true);
settings.setTextSize(WebSettings.TextSize.SMALLER);
} else {
LogUtils.e("------------>", "==string==" + string);
switch (string) {
case "teda":
settings.setSupportZoom(true);
settings.setBuiltInZoomControls(true);
settings.setTextSize(WebSettings.TextSize.LARGER);
break;
case "dahaozi":
settings.setSupportZoom(true);
settings.setBuiltInZoomControls(true);
settings.setTextSize(WebSettings.TextSize.LARGER);
break;
case "zhonghaozi":
settings.setSupportZoom(true);
settings.setBuiltInZoomControls(true);
settings.setTextSize(WebSettings.TextSize.NORMAL);
break;
case "xiaohaozi":
settings.setSupportZoom(true);
settings.setBuiltInZoomControls(true);
settings.setTextSize(WebSettings.TextSize.SMALLER);
break;
}
}
}
public static void zitiStyle2(final Context context, WebView webView) {
final WebSettings settings = webView.getSettings();
final SharedPreferences sharedPreferences = context.getSharedPreferences("hgz", Context.MODE_APPEND);
final SharedPreferences.Editor edit = sharedPreferences.edit();
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("修改昵称");
View view = LayoutInflater.from(context).inflate(R.layout.hgz_ziti_scale, null);
final TextView teda = (TextView) view.findViewById(R.id.teda);
final TextView dahaozi = (TextView) view.findViewById(R.id.dahaozi);
final TextView zhonghaozi = (TextView) view.findViewById(R.id.zhonghaozi);
final TextView xiaohaozi = (TextView) view.findViewById(R.id.xiaohaozi);
teda.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
teda.setTextColor(Color.YELLOW);
settings.setSupportZoom(true);
settings.setBuiltInZoomControls(true);
settings.setTextSize(WebSettings.TextSize.LARGEST);
LogUtils.e("----------->", "点击改为特大号字体");
edit.putString("teda1", "teda");
edit.commit();
LogUtils.e("----------->", "点击改为特大号字体2");
}
});
dahaozi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dahaozi.setTextColor(Color.YELLOW);
settings.setSupportZoom(true);
settings.setBuiltInZoomControls(true);
settings.setTextSize(WebSettings.TextSize.LARGER);
edit.putString("teda1", "dahaozi");
edit.commit();
}
});
zhonghaozi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
zhonghaozi.setTextColor(Color.YELLOW);
settings.setSupportZoom(true);
settings.setBuiltInZoomControls(true);
settings.setTextSize(WebSettings.TextSize.NORMAL);
edit.putString("teda1", "zhonghaozi");
edit.commit();
}
});
xiaohaozi.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
xiaohaozi.setTextColor(Color.YELLOW);
settings.setSupportZoom(true);
settings.setBuiltInZoomControls(true);
settings.setTextSize(WebSettings.TextSize.SMALLER);
edit.putString("teda1", "xiaohaozi");
edit.commit();
}
});
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.setView(view);//自定义的布局
//将builder创建
builder.create();
//将builder显示
builder.show();
}
}