"返回]在操作栏按钮 - 机器人。如何去"返回] ;?机器人、按钮、操作、何去

2023-09-08 08:55:54 作者:变的很复杂的情

图片

操作栏

Action Bar

我说的是(1号,中图),按钮与一个小箭头和应用程序图标,并在屏幕的左上方。当我们选择了黑色行动模板,它会自动定义的。

I'm talking about the (Number 1, in the pic), button with a little arrow and the app icon and the top left side of the screen. It is automatically defined when we select the "Black activity" template.

我的应用程序有一个pretty的庞大的层次图,得到了约25项活动了。 我基本上只是显示一些教程和一个可以根据分类导航。

My app has a pretty huge hierarchy graph, got about 25 activities now. I'm basically just showing a few tutorials and one can navigate to it according to the categories.

现在是后退(?)上的操作栏按钮啄是每一个画面我有,我也想保留它。在code显示没有错误,但是当我真正preSS该按钮,该应用程序停止工作。 我想,是刚刚复制的实际后退按钮的功能与(1号)按钮时,我表现出的形象。 当我preSS它,最上面的屏幕应该关门了,最后一个应该打开。只是关闭屏幕。

Now that "Back" (?) button thingy on action bar is on every screen I have, and I do want to keep it. The code shows no error, but when I actually press that button, the app stops working. What I want, is to just replicate the actual back button function with that (Number 1) button, that I showed in the image. When I press it, the top most screen should close, and the last one should open. Just close the screen.

我的尝试:

@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:

            NavUtils.navigateUpFromSameTask(this);
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

这是那个膨胀的越野车按钮与操作栏上的功能。我试着更换整个code,并呼吁完成的功能,但惨遭失败。 我无法找到专门针对此之上做了一个功能最左边的按钮...

this is the the function that inflates that buggy button along with the action bar. I tried to replace the entire code, and call "Finish" function, but that failed miserably. I was unable to find a function specifically made for that top left most button...

欲最顶部的屏幕叠(一个在前台)关闭,当触摸该按钮上。 如何做到这一点?

I want the top most screen on the stack(the one in the foreground) to close, when this button is touched. How to do this ?

推荐答案

我觉得最简单的办法就是如下:

I think the easiest way out is follows:

我假设,从活动 A 正在启动的活动 B 。现在从活动 B 要回去活性 A 在pressing行动左上角后退按钮酒吧。只需拨打 this.finish() ActivityName.this.finish()从那里:

I am assuming that from activity A you are starting the activity B. Now from activity B you want to go back to activity A on pressing the top left back button on action bar. simply call this.finish() or ActivityName.this.finish() from there:

@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
            this.finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

这应该完成您的当前活动。但是,如果你有很多的活动,那么你可能不得不这样做的所有活动。为了节省自己的这种努力,你可以做一个类可以称之为 AbstractActivity ;扩展活动。然后你就可以延长你的所有其他活动类来扩展这个类( AbstractActivity )。在 AbstractActivity ,你可以把上面的code。所以,现在那块code将适用于所有的活动和功能,将为所有这些实现。基本上,这样的事情(Inheritance)can随时使用,当有一些共同的特点,将适用于你的很多类。

This should finish your current activity. However if you have lot of activities, then you might have to do this in all the activities. To save yourself from that effort, you can make a class lets call it AbstractActivity; that extends Activity. Then you can extend all your other activity classes to extend that class(AbstractActivity). Inside AbstractActivity you can put the above code. So now that piece of code would be valid for all your activities and that feature would be implemented for all of them. Basically this sort of thing (Inheritance)can be used any time, when there are some common features which would be applicable to your many classes.

如果您收到任何错误,请发表您的 LogCat中如果您需要进一步的帮助。 希望这可以帮助你。

If you are receiving any errors, please do post your LogCat if you require further help. Hope this helps you.