小编use*_*415的帖子

Android Imagebutton更改Image OnClick

我刚drawableres文件夹下添加了一个新文件夹.在drawable文件夹中,我ic_launcher.pngdrawable-hdpi文件夹中复制了该文件.ImageButton当我按下按钮时,我想通过新的标准图像更改标准图像.我写了一些代码,但是当我启动应用程序时,它崩溃了.

Button imgButton; 

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    findViewById(R.id.imgButton).setOnClickListener(imgButtonHandler);      
}

View.OnClickListener imgButtonHandler = new View.OnClickListener() {

    public void onClick(View v) {

        imgButton.setBackgroundResource(R.drawable.ic_launcher);

    }
};
Run Code Online (Sandbox Code Playgroud)

编辑:我改为这个,这也行不通.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    imgButton = (Button) findViewById(R.id.imgButton);
    imgButton.setOnClickListener(imgButtonHandler);
}


View.OnClickListener imgButtonHandler = new View.OnClickListener() {

    public void onClick(View v) {
        imgButton.setBackgroundResource(R.drawable.ic_launcher);

    }
};
Run Code Online (Sandbox Code Playgroud)

编辑2:这个工作.谢谢大家.

ImageButton button;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    button= (ImageButton)findViewById(R.id.imgButton); …
Run Code Online (Sandbox Code Playgroud)

android image imagebutton

30
推荐指数
3
解决办法
11万
查看次数

Webview - 在显示网站之前更改页面源?

我有一个网站.在网站上,有一个文本"Pic".当我第一次在Webview中显示网站时,我可以将文本更改为"PicGreat".这有效!

但是,稍后当用户点击链接(网站上的某个位置)时,我会将用户转发到新的HTML网站.在我展示网站之前,我想将文本"Pic"更改为"PicGreat".

我该怎么做?我应该编写一个函数,然后在"public boolean shouldOverrideUrlLoading"中调用该函数吗?

我在Stackoverflow上找到了类似的问题,但没有解决. 如何设置webview客户端

main.xml中

<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/webview"
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
/>
Run Code Online (Sandbox Code Playgroud)

AndroidManifest.xml中

<uses-permission android:name="android.permission.INTERNET" />
Run Code Online (Sandbox Code Playgroud)

WebTest.java

public class WebTestActivity extends Activity {

 WebView mWebView;
 String rline = "";

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);

 setContentView(R.layout.main);

 mWebView = (WebView) findViewById(R.id.webview);
 mWebView.getSettings().setJavaScriptEnabled(true);

 HttpURLConnection urlConnection = null;
 try
 {
 URL url = new URL("http://www.picSite.com/");
 urlConnection = (HttpURLConnection) url.openConnection();
 InputStream in = new BufferedInputStream(urlConnection.getInputStream());
 BufferedReader rd = new …
Run Code Online (Sandbox Code Playgroud)

android webview webviewclient

5
推荐指数
1
解决办法
2829
查看次数

标签 统计

android ×2

image ×1

imagebutton ×1

webview ×1

webviewclient ×1