如何将图像按钮链接到Android的Facebook专页 [英] how to link the image button to a facebook page in android

查看:155
本文介绍了如何将图像按钮链接到Android的Facebook专页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新到Android ....

i am new to android ....

我已经设计了在那里我有4图像按钮视图

i have designed a view where i have created 4 image buttons

在一个已经去到Facebook网址
        第二个有去Twitter的网址
        第三个必须去YouTube网址等这样的
        第四至LinkedIn

in that one has to go to facebook url second has to go twitter url third has to go to youtube url etc like that fourth to linkedin

但我不知道如何配置按钮发送网址及以下

but i dont know how to configure the button to send a url and the page must inside the same design view shown below

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/apple" >



<Button
    android:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#2C3539"
    android:gravity="center"
    android:text="@string/apple"
    android:textColor="#FFFFFF"
    android:textSize="22sp" />

<Button
    android:id="@+id/video"
    android:layout_width="match_parent"
    android:layout_height="55dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_toRightOf="@+id/music"
    android:background="#2C3539"
    android:text="@string/video"
    android:textColor="#FFFFFF"
    android:textColorHint="@color/black"
    android:textSize="20sp" />

<Button
    android:id="@+id/music"
    android:layout_width="160dp"
    android:layout_height="55dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:background="#2C3539"
    android:text="@string/music"
    android:textColor="#FFFFFF"
    android:textColorHint="@color/black"
    android:textSize="20sp" />

<TableLayout
    android:id="@+id/tableLayout1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/main"
    android:layout_marginLeft="41dp"
    android:layout_marginTop="72dp" >

</TableLayout>

<ImageButton
    android:id="@+id/twitter1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/facebook1"
    android:src="@drawable/twitter" />

<ImageButton
    android:id="@+id/facebook1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/main"
    android:src="@drawable/facebook" />

<ImageButton
    android:id="@+id/youtube1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/twitter1"
    android:src="@drawable/youtube" />

<ImageButton
    android:id="@+id/instagram1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/youtube1"
    android:src="@drawable/instagram_icon" /></RelativeLayout>

以上code是这样的,如果我在Facebook上图片的点击,然后它来填充这个链接
https://www.facebook.com/apple.fruit

和环节都填充到体内(图像显示)

And link has to populate onto body (shown in image)

任何人都可以写后端code如何使用按钮

can anyone write the backend code how to use the button

我已创建了一个.java文件

i have created one java file

package com.lay.background;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;









public class AppleActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.apple);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.second, menu);
        return true;
    }   }

任何人都可以请解决code。如果有任何疑问,请发表评论

Can anyone please resolve the code if any queries please comment

推荐答案

对于每个按钮,你可以像这样特定的URL

for each button you can pass the intent with specific URL like this

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

例如,如果你的按钮facebookButton然后在活动像这样使用它:

For example if your button is facebookButton then use it in your Activity like this:

ImageButton facebookButton = (ImageButton)findViewById(R.id.facebook1);
  facebookButton.setOnClickListener(new View.onClickListener() 
   {  
        public void onClick(View arg0) 
          { 
               Intent browserIntent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.facebook.com/apple.fruit"));
                startActivity(browserIntent);

               }
         });

其他的方式将被装入您的网址进入的WebView。

other way would be loading your URL into a WebView.

myWebView.loadUrl(http://"+tempUrl);

至于失踪的http://我只是做这样的事情:

As for the missing "http://" I'd just do something like this:

if (!url.startsWith("http://") && !url.startsWith("https://"))
   url = "http://" + url;

在XML布局文件中添加的WebView:

Adding WebView in xml layout file:

<WebView android:id="@+id/webview"
android:layout_width="fill_parent" android:layout_height="50dip"/>

添加视图内容与您的网址MainActivity:

Add the WebView content with your Url in MainActivity :

 // Enable javascript for the view
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebview.setWebViewClient(new WebViewClient() {
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            Toast.makeText(this, description, Toast.LENGTH_SHORT).show();
        }
    });

    mWebview .loadUrl("http://www.facebook.com/apple.fruit");

这篇关于如何将图像按钮链接到Android的Facebook专页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆