简体   繁体   English

Android - 全屏透明按钮

[英]Android - full screen transparent button

Is it possible to make a full screen button that is transparent so no matter where the user clicks the button is activated? 是否可以制作一个透明的全屏按钮,无论用户点击按钮的位置是什么?

Below is some basic java that shows a button and when pressed starts a new intent. 下面是一些显示按钮的基本java,按下时会启动一个新意图。 I also added the main.xml layout but I am not sure how to update it so the buttons fills the screen but is transparent. 我还添加了main.xml布局,但我不知道如何更新它,以便按钮填充屏幕但是透明。

package com.MeetingManager;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;

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

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.main);



    layout.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent e) {
            Intent myIntent = new Intent(MeetingManager.this,CreateMeeting.class);
            startActivityForResult(myIntent, 0);
        }
    });

}



}

XML: 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"
    android:background="@drawable/meetingbg"
    >
    <TableRow android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/tableRow5">
        <Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
    </TableRow>

</LinearLayout>

If listening for user interaction via tapping on screen is your aim, I would recommend added a touch listener to your LinearLayout. 如果您通过点击屏幕来监听用户互动是您的目标,我建议您为LinearLayout添加一个触控侦听器。 This removes the need for a Button. 这消除了对Button的需要。

Eg 例如

LinearLayout layout = (LinearLayout) findViewById(R.id.your_layout);

layout.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return false;
        }
    });
});

XML: XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/your_layout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/meetingbg"
    >
    <TableRow android:layout_height="wrap_content" android:layout_width="match_parent" android:id="@+id/tableRow5">
        <Button android:text="Button" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
    </TableRow>

</LinearLayout>

You may have to include the following imports: 您可能必须包含以下导入:

import android.view.View.OnTouchListener;
import android.view.MotionEvent;

尝试在后台使用null android:background="@null"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM