【问题标题】:How to minimize whole application in android?如何最小化android中的整个应用程序?
【发布时间】:2011-11-23 17:31:24
【问题描述】:

我是开发安卓应用的。我已经完成了更多,但我想最小化选项。我用过标签栏。在那我想最小化标签。当用户单击最小化选项卡以最小化整个应用程序时。 我的标签栏代码为..

    public class tabbar extends TabActivity implements OnTabChangeListener {
    private Context mContext;
    TabHost tabHost;
    int tabload=0;
    private AlertDialog alertDialog;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tabbar);
        //mContext=this;

        /** TabHost will have Tabs */
        tabHost = (TabHost)findViewById(android.R.id.tabhost);
        tabHost.setOnTabChangedListener(this);



        /** TabSpec used to create a new tab.
         * By using TabSpec only we can able to setContent to the tab.
         * By using TabSpec setIndicator() we can set name to tab. */

        /** tid1 is firstTabSpec Id. Its used to access outside. */
        TabSpec firstTabSpec = tabHost.newTabSpec("tab_id1");
        TabSpec secondTabSpec = tabHost.newTabSpec("tab_id2");
        TabSpec thirdTabSpec = tabHost.newTabSpec("tab_id3");


        /** TabSpec setIndicator() is used to set name for the tab. */
        /** TabSpec setContent() is used to set content for a particular tab. */
        firstTabSpec.setIndicator("FRIENDS").setContent(new Intent(this,view_friends.class));
        secondTabSpec.setIndicator("GROUPS").setContent(new Intent(this,groups.class));
        thirdTabSpec.setIndicator("SIGN OUT").setContent(new Intent(this,signout.class));


        /** Add tabSpec to the TabHost to display. */
        tabHost.addTab(firstTabSpec);
        tabHost.addTab(secondTabSpec);
        tabHost.addTab(thirdTabSpec);



    }



        @Override
        public void onTabChanged(String tabId) {
        // TODO Auto-generated method stub

         for(int i=0;i<tabHost.getTabWidget().getChildCount();i++)
            {
                     tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#343333")); //unselected
            }
                      tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#f1a026"));     // selected
    //         if(tabId.equals("tab_id1")){
    //             LocalActivityManager manager = getLocalActivityManager();
    //             manager.destroyActivity("tab_id1", true);
    //             manager.startActivity("tab_id1", new Intent(this, view_friends.class));
    //         }

    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        tabHost.setCurrentTab(2);
        System.gc();
    }


}

在此代码中如果有任何更正需要请帮助...

给我一​​个示例代码..

【问题讨论】:

  • 定义“最小化”。你在找Activity.finish()吗?
  • 你现在想要什么?您想要与“主页”按钮相同的行为吗?不是很清楚。
  • 是的,我希望在我的标签点击中主页按钮行为

标签: android tabbar


【解决方案1】:

我不确定您所说的最小化是什么意思。如果您想隐藏您的应用并向用户显示主屏幕,您可以使用以下意图。

Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);

虽然如果用户想要隐藏您的应用,主页按钮已经绰绰有余

【讨论】:

  • 这正是我想要的。
  • 如何从其他应用程序中最小化?
【解决方案2】:

尝试调用此moveTaskToBack(true); 布尔值。

【讨论】:

  • 这会导致意想不到的副作用,它只是把活动放到后台,而不是整个应用程序......
  • 好的,但这对于只有一个活动且拥有launchMode="singleTop" 的应用程序非常有用。感谢您的投票。
  • 但是问题是关于最小化整个应用程序的问题!
猜你喜欢
  • 2016-03-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多