【发布时间】:2013-12-19 21:16:36
【问题描述】:
我在这方面已经有一段时间了(3 天)。我正在尝试使用 Eclipse 制作一个 android 应用程序。我想要两个图像按钮。每个链接到不同的站点。我一直没能做到。我已经能够使用 webview 用一个按钮打开一个网页,但不是两个。我已经开始尝试使用 Intent 代替,因为我在某处读到那是更好的方法。最终,我想要做的是在应用程序中打开页面并使用后退按钮返回每个按钮/页面的应用程序主屏幕。到目前为止,这是我的代码。
MainActivity.java
package com.modsbyus.onoff;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void Light()
{
Intent intent = new Intent(Intent.ACTION_VIEW, uri.parse("https://agent.electricimp.com/BGSBpog28J0u?led=1"));
startActivity(intent);
}
public void Light1()
{
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://agent.electricimp.com/BGSBpog28J0u?led=0"));
startActivity(intent);
}
}
和我的布局 activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageButton
android:id="@+id/imageButton1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android.onClick="Light1"
android:clickable="true"
android:src="@drawable/ic_launcheronswitch" />
<ImageButton
android:id="@+id/imageButton2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android.onClick="Light"
android:clickable="true"
android:src="@drawable/ic_launcheroffswitch" />
</LinearLayout>
你们能提供的任何帮助都会很棒。 谢谢!
【问题讨论】:
标签: android eclipse button android-intent