2011-10-08 6 views
3

전체 화면 버튼을 투명하게 만들 수있어 사용자가 버튼을 클릭 한 위치에 관계없이 투명하게 할 수 있습니까?Android - 전체 화면 투명 버튼

다음은 버튼을 표시하고 눌렀을 때 새로운 의도를 시작하는 몇 가지 기본 Java입니다. 또한 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 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> 

답변

7

null를 사용하는, 내가 터치 리스너를 추가하는 것이 좋습니다 것입니다 LinearLayout에 추가하십시오. 버튼이 필요 없습니다.

예.

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

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

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> 
다음과 같은 수입을 포함 할 수 있습니다

:

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

+0

고마워! +1 지금 구현 중입니다. – Denoteone

+0

위의 코드를 추가하려고하면 R.java 파일을 다시 작성하려고합니다 (불가능). 누락 된 것이 있습니까? 위의 코드를 업데이트했습니다. – Denoteone

+0

XML에서 레이아웃에 ID를 추가하는 방법과 onTouchListener를 추가하기 전에 이것을 프로그램 방식으로 가져 오는 방법을 보여주기 위해 내 소스를 편집했습니다. 희망이 도움이 – Ljdawson

1

시도가 배경 android:background="@null"

+0

그래서 버튼의 배경을 제거 할 수 있습니까? 페이지의 다른 모든 요소를 ​​오버레이하는 방법은 무엇입니까? – Denoteone

+0

버튼이 하나 뿐인 경우 RelativeLayout을 사용할 수 있습니다. [가져 오기/내릴 수 있습니다. 29) – salahy

관련 문제