【问题标题】:Something like a Navigation Controller for Android?类似于 Android 的导航控制器?
【发布时间】:2012-07-06 13:42:18
【问题描述】:

我是 Android 开发的新手,但我在 iOS/Java 开发方面的水平很高。

我想使用导航控制器之类的东西在我的 Android 应用程序中的视图(我知道的活动)之间移动。我应该使用什么?

感谢您的建议。

【问题讨论】:

    标签: android navigationcontroller


    【解决方案1】:

    查看旧类 android.app.TabActivity 或称为 Fragment 的新类。最后 TabActivity 应该在大多数 IDE 中都可用。

    这是一个标签活动的例子:

    public class TabbedActivity extends TabActivity {
    
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            Resources res = getResources(); // Resource object to get Drawables
            TabHost tabHost = getTabHost();  // The activity TabHost
            TabHost.TabSpec spec;  // Resusable TabSpec for each tab
            Intent intent;  // Reusable Intent for each tab
    
            // Create an Intent to launch an Activity for the tab (to be reused)
            intent = new Intent().setClass(this, TasksActiveListActivity.class);
    
            // Initialize a TabSpec for each tab and add it to the TabHost   
            spec = tabHost.newTabSpec("artists").setIndicator("Tasks",
                              res.getDrawable(R.drawable.ic_tab_artists))
                          .setContent(intent);
            tabHost.addTab(spec);
    
            // Do the same for the other tabs
            intent = new Intent().setClass(this, StatisticActivity.class);
            spec = tabHost.newTabSpec("albums").setIndicator("Statistic",
                              res.getDrawable(R.drawable.ic_tab_artists))
                          .setContent(intent);
            tabHost.addTab(spec);  
    
    
            intent = new Intent().setClass(this, PurchaseActivity.class);
            spec = tabHost.newTabSpec("albumz").setIndicator("Bonuses",
                              res.getDrawable(R.drawable.ic_tab_artists))
                          .setContent(intent);
            tabHost.addTab(spec);
    
    
            tabHost.setCurrentTab(0);
        }
    
    
    
    }
    

    【讨论】:

    • 两者都可以在 Eclipse 中使用,我要看看这个。谢谢!
    【解决方案2】:

    使用片段而不是旧的和已弃用的 TabActivity
    请查看这篇文章: Android UINavigationController-like feature

    【讨论】:

      【解决方案3】:

      Intents 用于在视图/活动之间导航。检查Intent

      【讨论】:

      • OP 询问用户可见的 UI 元素,而不是关于打开新屏幕的编程方式。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-14
      • 2019-12-18
      • 2017-05-14
      • 1970-01-01
      • 1970-01-01
      • 2020-09-15
      相关资源
      最近更新 更多