首先在按钮那边需要做存储 SharedPreUtil.saveInt(DetailContentActivity.this, Constant.TEXT_SIZE,channelType); intTosize(channelType);
public class SharedPreUtil {
private static final String SMART_BJ = "smart_bj"; //存储是否第一次启动
//存储boolean值
public static void saveBoolean(Context context, String keyName , boolean value){
SharedPreferences sp = getSharedPreferences(context);
sp.edit().putBoolean(keyName,value).apply();
}
//获取boolean值
public static boolean getBoolean(Context context, String keyName){
SharedPreferences sp = getSharedPreferences(context);
return sp.getBoolean(keyName,false);
}
public static void saveInt(Context context, String keyName , int value){
SharedPreferences sp = getSharedPreferences(context);
sp.edit().putInt(keyName,value).commit();
}
public static int getInt(Context context, String keyName){
SharedPreferences sp = getSharedPreferences(context);
return sp.getInt(keyName,2);
}
private static SharedPreferences getSharedPreferences(Context context){
return context.getSharedPreferences(SMART_BJ, Context.MODE_PRIVATE);
}
}
private void intTosize(int which) {
switch (which) {
case MainBottomLayout.ChannelType.CHANNEL_SMALL:
textSize_sp.edit().putInt(Constant.TEXTSIZE_INTEGER,
Constant.TEXTSIZE_SMALL).commit();//这一行代表列表字体初始化
settings.setTextSize(WebSettings.TextSize.SMALLER);//这一行代表webview中字体大小
break;
case MainBottomLayout.ChannelType.CHANNEL_MIDDLE:
textSize_sp.edit().putInt(Constant.TEXTSIZE_INTEGER,
Constant.TEXTSIZE_CENTRE).commit();
settings.setTextSize(WebSettings.TextSize.NORMAL);
break;
case MainBottomLayout.ChannelType.CHANNEL_BIG:
textSize_sp.edit().putInt(Constant.TEXTSIZE_INTEGER,
Constant.TEXTSIZE_BIG).commit();
settings.setTextSize(WebSettings.TextSize.LARGER);
break;
case MainBottomLayout.ChannelType.CHANNEL_BIGGER:
textSize_sp.edit().putInt(Constant.TEXTSIZE_INTEGER,
Constant.TEXTSIZE_MAX_BIG).commit();
settings.setTextSize(WebSettings.TextSize.LARGEST);
break;
}
}
ok,初始化这边就开始了,接着是webview中要怎么做处理呢
int textSize = SharedPreUtil.getInt(this, Constant.TEXT_SIZE);//获取到webview字体 intTosize(textSize);
以上就是webview中字体大小了
接下来是最后一个,那就是列表的字体大小了,这个相信大家都不难吧
holder.tv_shorttitle.setTextSize(context.getSharedPreferences(Constant.TEXT_SIZE1, context.MODE_PRIVATE).getInt(Constant
.TEXTSIZE_INTEGER, Constant.TEXTSIZE_CENTRE));
就是这句啦,在原本上面的那句先初始化了列表字体大小,在这里直接获取。
以上就是字体大小的设置了,结合在一起用了好一会儿,哈哈