简体   繁体   English

在Android中,如何在水龙头上更改屏幕?

[英]How to change screen on a tap, in Android?

I have a really simple Android Application - pretty much the most simple possible. 我有一个非常简单的Android应用程序-几乎是最简单的。

I have two different setContentView calls. 我有两个不同的setContentView调用。 I want the second one to be called after the user taps on the screen. 我希望在用户点击屏幕后调用第二个。 Everything works otherwise. 一切正常。

How do I get that view to pop up when the user taps? 用户点击时如何弹出该视图?

Here is my MainActivity class: 这是我的MainActivity类:

package com.example.myfirstapp;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;

public class MainActivity extends Activity {
    public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";

    @Override
    protected 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.activity_main);
        setContentView(R.layout.activity_main2);


    }

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


}

And here is activity_main2 : 这是activity_main2

<LinearLayout 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"
    android:orientation="horizontal"
    android:background="@drawable/corporatesplash" >

</LinearLayout>

So if I undestand correctly there is a button on your screen. 因此,如果我不正确地理解您的屏幕上有一个按钮。 If user clicks the button, the proper action is being called (sendMessage). 如果用户单击该按钮,则将调用适当的操作(sendMessage)。 If user clicks any area on screen apart from the button, the other thing is being called (setContentView or w/e). 如果用户单击屏幕上除按钮之外的任何区域,则将调用另一项(setContentView或w / e)。 Is that correct? 那是对的吗?

If yes, I would advice you to create a View, that you would place under the Button, filling the screen (for example in RelativeLayout). 如果是,我建议您创建一个视图,将该视图放置在Button下,填充屏幕(例如,在RelativeLayout中)。 And add to it a OnTouchListener . 并添加一个OnTouchListener

you have to make one default contentview and the other 您必须使一个默认的contentview和另一个

    setContentView(R.layout.activity_main);
         @Override
                    public boolean onTouch(View v, MotionEvent event) {

                        if(firstTap){

                            firstTap = false;
                            reloadclass(); 
// use any method for reload the class i recommend to use intent and reload the class 
//and also use Put string through intent and set variable firsttap and 
//check if the click is first time or not

                        }
                        else
                        {
                                firstTap = true;


                        }
                        return false;
                    }
                });

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

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