0

Androidについて質問があります。私はAndroidが初めてで、メインのナビゲーション要素としてタブを持つ小さなアプリを作ろうとしています. タブの正しい操作方法が 100% わかりません。多分あなたは私をそこに導くことができます。

私の知る限り、基本的に2つの異なるオプションがあります。アクション バーまたは TabHost でタブを使用できます。私の意見では、前者が正しい方法です。ここでの長所と短所は何ですか?

アクション バーでタブを使用する場合は、3 つ以下のタブを使用することをお勧めします。より多くのナビゲーション オプションが必要な場合はどうすればよいですか (「...」オプションがある iOS タブとは異なります)。

別の種類のナビゲーション要素を使用する必要がありますか? (私の場合、4つの「タブ」があると思います)

前もって感謝します!

4

4 に答える 4

3

アクションバーは間違いなく行く方法です。TabHost は非推奨であり、Google は、ICS 後の設計哲学に実際に適合するため、アクション バーを使用することを好みます。

ActionBarSherlockを使用して、2.1 (Eclair) 以降のすべての Android バージョンをサポートできます。

開始するためのチュートリアルを次に示します。

http://avilyne.com/?p=180

http://xrigau.wordpress.com/2012/03/15/using-an-actionbar-in-your-application-with-actionbarsherlock/

ビデオ チュートリアル:

http://www.youtube.com/watch?v=avcp6eD_X2k

http://www.youtube.com/watch?v=4mOMOh-fH-c

于 2012-12-14T17:08:55.547 に答える
1

このようなことを試してください:

Activity sampleActivity = (Activity) View.getContext();
ActionBar actionBar = sampleActivity.getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Tab tab = actionBar.newTab();
tab.setText("This is the name of the tab");
actionBar.addTab(tab, true);
于 2012-12-14T18:10:57.670 に答える
0

彼/彼女の問題を解決するためにこの例を使用してください

タブ用のこのメインxmlファイル

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="5dp">
    <TabWidget`enter code here`
        android:id="@android:id/tabs"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp" />
</LinearLayout>

javaファイル

     @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_layout);

    Resources ressources = getResources();
    TabHost tabHost = getTabHost();

            Intent intentAndroid = new Intent().setClass(this,FirstClass.class);

    TabSpec tab1 = tabHost
            .newTabSpec("Android")
            .setIndicator("",ressources.getDrawable(R.drawable.icon_android_config))
            .setContent(intentAndroid);

Intent intentAndroid2 = new Intent().setClass(this,FirstClass.class);

    TabSpec tab2 = tabHost
            .newTabSpec("Android")
            .setIndicator("",ressources.getDrawable(R.drawable.icon))
            .setContent(intentAndroid2);


            tabHost.addTab(tab1);
    tabHost.addTab(tab2);

           tabHost.setCurrentTab(0);

}

于 2012-12-14T17:08:36.387 に答える
0
public int getCount() {
            // Show 3 total pages.
            return 5;
        }


        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case 0:
                    return "Items";
                case 1:
                    return "Food";
                case 2:
                    return "Drink";
                case 3:
                    return "soft";
                case 4:
                    return "warm";
            }
            return null;
        }
    }
于 2016-11-12T11:33:11.523 に答える