WebView 的button多操作
来源:互联网 发布:软件销售服务协议 编辑:程序博客网 时间:2024/06/01 23:22
第一次写博客,不会写呢,我能力不大,望各位前辈多指教!
(不知道怎么上图,就不上图了)
APP 2012-11-16
package gg.demo.web;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
/**不知道这个算不算是???
*
* 这个思路方向可以考虑,剩下的你看看。
*
*
* @author APP
*
*/
public class MainActivity extends Activity implements OnClickListener {
MyWeb my;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
my = (MyWeb) this.findViewById(R.id.webView);
this.findViewById(R.id.one).setOnClickListener(this);
this.findViewById(R.id.two).setOnClickListener(this);
this.findViewById(R.id.three).setOnClickListener(this);
my.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
super.shouldOverrideUrlLoading(view, url);
view.loadUrl(url);
return true;
}
});
}
String tag = "System.out";
String str1 = "http://www.baidu.com";
String str2 = "http://www.163.com";
String str3 = "http://www.csdn.net";
public void onClick(View v) {
switch (v.getId()) {
case R.id.one:
my.load(MainActivity.this, str1);
break;
case R.id.two:
my.load(MainActivity.this, str2);
break;
case R.id.three:
my.load(MainActivity.this, str2);
break;
}
}
}
重写webView.
package gg.demo.web;
import java.util.ArrayList;
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.webkit.WebView;
@SuppressLint("NewApi")
public class MyWeb extends WebView {
private ArrayList<WebView> webs = new ArrayList<WebView>();
private MyWeb web = this;
public MyWeb(Context context) {
super(context);
}
public MyWeb(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyWeb(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public MyWeb(Context context, AttributeSet attrs, int defStyle,
boolean privateBrowsing) {
super(context, attrs, defStyle, privateBrowsing);
}
private int flag = 0;
public void load(Context context, String url) {
WebView w = this;
webs.add(w);
w.setTag(flag);
flag++;
w.loadUrl(url);
}
public void stop(View v) {
int i = Integer.parseInt(v.getTag().toString());
WebView webView = webs.get(i);
webView.stopLoading();
}
public void stopOthers(View v) {
int j = Integer.parseInt(v.getTag().toString());
for (int k = 0; k < webs.size(); k++) {
if (j != k) {
WebView we = webs.get(k);
we.stopLoading();
}
}
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/top"
android:layout_width="fill_parent"
android:layout_height="45dip"
android:orientation="horizontal" >
<Button
android:id="@+id/one"
android:layout_width="wrap_content"
android:layout_height="45dip"
android:text="button-1" />
<Button
android:id="@+id/two"
android:layout_width="wrap_content"
android:layout_height="45dip"
android:text="button-22" />
<Button
android:id="@+id/three"
android:layout_width="wrap_content"
android:layout_height="45dip"
android:text="button-333" />
</LinearLayout>
<gg.demo.web.MyWeb
android:id="@+id/webView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/top" />
</RelativeLayout>
- WebView 的button多操作
- button的操作
- webview的基本操作
- webview的一些操作
- Button多选操作
- 针对单个Button的操作
- 关于button按钮的操作
- 在自定义Dialog上,点击Button实现WebView的跳转
- Android WebView的几个操作
- android WebView的低级操作
- MFC Radio Button 和 Combox Button的简单操作
- webview操作
- DataGrid关于button的相关操作
- 【Android】Android WebView 的几个操作
- 【Android】Android WebView 的几个操作
- WebView中的视频全屏的相关操作
- 【Android】Android WebView 的几个操作
- appium 操作 iOS webview 的原理
- 关于在WORD中MathType编辑公式居中及编号右对齐问题的解决办法
- 多重继承类构造函数的声明
- 信号与系统3:单位阶跃,单位响应以及系统性质
- 等概率随机洗牌算法
- Thinking in UML 第1, 2章笔记
- WebView 的button多操作
- 学习笔记之MFC添加背景图片
- Linux下正则表达式匹配性能
- 这周零碎总结与js实现分页案例
- ★一些实用的编程代码 C/C++
- 基于Jquery的图片切换八种效果效果
- 关于smarty中templates_c中的文件生成和命名
- 【转】android:自定义layout动态改变view位置和大小
- Java的一些高级特性(一)——Java 7新特性