2014-01-25 49 views
0

我對Android和Eclipse是全新的。如何在android應用程序中添加背景圖片和鏈接按鈕?

我只是想創建一個應用程序。我正在嘗試設置一個背景圖片(該圖片中的應用徽標視圖以及一些文本將位於其中),並且希望製作一個鏈接到我的網站的按鈕。

如何設置背景圖片,以及如何我可以通過點擊該按鈕,虛擬用戶發送到我的網站?

謝謝大家。最良好的祝願......

回答

0

試試這個: 創建活動,並添加代碼 -

final Button btn = (Button) findViewById(R.id.button); 
    view = (WebView) findViewById(R.id.web); 

    btn.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      view.loadUrl("http://myweb.in"); 
     } 
    }); 

與代碼 -

<Button 
    android:id="@+id/button" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="Go To Web" 
    android:layout_centerInParent="true"/> 

<WebView 
    android:id="@+id/web" 
    android:layout_below="@+id/button" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"/> 

希望這項工作創建一個XML ..

+0

謝謝你這麼多的響應。 – emrahakman

2

這是xml代碼。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@null" > 

    <Button 
     android:id="@+id/btnViewWebsite" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginBottom="54dp" 
     android:text="Visit Website" /> 

</RelativeLayout> 

在activity中設置activity的onClick動作。你可以在這裏使用這個

Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com")); 
startActivity(browserIntent); 

另外在寫入@null的地方,傳遞圖像。 @繪製/ some_image

確保添加Internet權限在manifest.xml文件

<uses-permission android:name="android.permission.INTERNET" /> 
+0

非常感謝您的回覆 – emrahakman

+0

沒問題,如果有效,我會要求您將其標記爲已接受,因爲它將在未來幫助其他人。 – Hardik4560

0

在XML:

android:background="@drawable/imgname" 
在Java

_ImageView1.setImageResource(resId);//resId R.Drawable.imgname 
+0

非常感謝您的回覆 – emrahakman