如何最小化Android中的整个应用程序?

发布于 2024-12-05 22:41:07 字数 2700 浏览 0 评论 0原文

我开发了android应用程序。我已经完成了更多内容,但我想尽量减少选择。我用过标签栏。我想最小化选项卡。当用户单击最小化选项卡时最小化整个应用程序。 我的标签栏代码为..

    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();
    }


}

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

给我一个示例代码..

I was developed android application. More over i have completed, but i want to minimize option. I have used tab bar. In that i want to minimize tab. When user click minimize tab to minimize whole application.
my tabbar code as..

    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();
    }


}

In this code if any correction need please help...

give me a sample code..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生寂 2024-12-12 22:41:07

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

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

尽管如果用户想要隐藏您的应用程序,主页按钮就足够了

I'm not sure what you mean by minimize. If you want to hide your app and present the user with the homescreen you can use the following intent.

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

Although the Home button is more than sufficient if a user wants to hide your app

茶底世界 2024-12-12 22:41:07

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

Try calling this moveTaskToBack(true); boolean.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文