原博客地址: http://blog.csdn.net/codeemperor/article/details/49701543
新闻详情的布局如下:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/title_red_bg" > <ImageButton android:id="@+id/btn_back" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginLeft="5dp" android:background="@null" android:src="@drawable/back" /> <ImageButton android:id="@+id/btn_share" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_marginRight="5dp" android:background="@null" android:src="@drawable/icon_share" /> <ImageButton android:id="@+id/btn_size" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_marginRight="5dp" android:layout_toLeftOf="@id/btn_share" android:background="@null" android:src="@drawable/icon_textsize" /> </RelativeLayout> <FrameLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" > <WebView android:id="@+id/wv_web" android:layout_width="match_parent" android:layout_height="match_parent" /> <PRogressBar android:id="@+id/pb_progress" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:indeterminateDrawable="@drawable/custom_progress" /> </FrameLayout></LinearLayout>我在在新闻详情页设置改变字体ImageButton的点击事件后进入以下方法:/** * 显示选择对话框 */ private void showChooseDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); String[] items = new String[] { "超大号字体", "大号字体", "正常字体", "小号字体", "超小号字体" }; builder.setTitle("字体判断"); builder.setSingleChoiceItems(items, mCurrentItem, new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { mCurrentChooseItem = which; } }); builder.setPositiveButton("确定", new OnClickListener() { WebSettings settings = mWebView.getSettings(); @Override public void onClick(DialogInterface dialog, int which) { switch (mCurrentChooseItem) { case 0://就是通过设置settings的setTextSize来改变字体的大小 settings.setTextSize(TextSize.LARGEST); break; case 1: settings.setTextSize(TextSize.LARGER); break; case 2: settings.setTextSize(TextSize.NORMAL); break; case 3: settings.setTextSize(TextSize.SMALLER); break; case 4: settings.setTextSize(TextSize.SMALLEST); break; default: break; } //保存用户选择的状态 mCurrentItem = mCurrentChooseItem; } }); builder.setNegativeButton("取消", null); builder.show(); }
新闻热点
疑难解答