【问题标题】:how to add just an background image and a link button in android application?如何在 android 应用程序中仅添加背景图像和链接按钮?
【发布时间】:2014-02-16 10:04:33
【问题描述】:

我对 Android 和 Eclipse 完全陌生。

我只想创建一个应用程序。我正在尝试设置背景图像(该图像中的应用徽标视图和一些文本将包含在其中)并且想要制作一个链接到我的网站的按钮。

如何设置背景图片以及如何通过单击虚拟按钮将用户发送到我的网站?

谢谢大家。最良好的祝愿......

【问题讨论】:

    标签: android eclipse image background hyperlink


    【解决方案1】:

    这是 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的地方,传递图片。 @drawable/some_image

    确保在manifest.xml 文件中添加 Internet 权限

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

    【讨论】:

    • 没问题,如果有效,我会要求您将其标记为已接受,因为它将帮助其他人。
    【解决方案2】:

    试试这个: 创建一个活动并添加代码-

    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");
            }
        });
    

    并用代码创建一个xml-

     <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"/>
    

    希望这项工作..

    【讨论】:

      【解决方案3】:

      在xml中:

       android:background="@drawable/imgname" 
      

      在java中:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-11-04
        • 1970-01-01
        • 2016-04-13
        • 1970-01-01
        相关资源
        最近更新 更多