Android 如何做类似“的事情”;触按任意位置可继续“;?
您将如何执行“触碰任何位置以继续”之类的操作。为整个屏幕的布局设置一个onclick侦听器。就这么简单。Android 如何做类似“的事情”;触按任意位置可继续“;?,android,Android,您将如何执行“触碰任何位置以继续”之类的操作。为整个屏幕的布局设置一个onclick侦听器。就这么简单。 给“主”布局一个id 将侦听器设置为主布局 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=&quo
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:id="@+id/mainLayout"> //<--- Provide ID
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/>
</RelativeLayout>
如何设置布局的onclicklistener?@SeungUn:请参阅
public class MainActivity extends AppCompatActivity {
private RelativeLayout layout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
layout = (RelativeLayout)findViewById(R.id.mainLayout);
layout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Clicked", Toast.LENGTH_SHORT).show();
}
});
}
}