0

对于我的应用程序,我试图将按钮放在类似于微信应用程序的所有活动的底部,如下图所示:

在此处输入图像描述

现在我想到的一种方法是简单地<ImageButton>在每个活动的底部添加 s 但我认为微信不会这样做,因为您可以在活动之间滑动并且没有onCreate触发,活动总是在那里,当滑动或触摸特定时简单地切换按钮。

我做了研究,发现一个可以使用split action bar甚至ViewFlipper. 操作栏拆分是没有问题的,因为按钮将被移回操作栏,例如在横向模式下,因为我希望按钮总是像微信一样出现在底部。我看到的另一个选项是Tabbed界面,但我看到了它,它可以出现在操作栏下方,这与微信不同,即使操作栏也会根据活动进行更改。

问题:有谁知道微信用什么来实现这个功能,所以我可以实现同样的功能?

4

2 回答 2

1
here is code main class 


public class TabSample extends TabActivity {
    /** Called when the activity is first created. */

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        setTabs();

    }

    private void setTabs() {

        addTab("Wechat", R.drawable.tab_home, ShowList.class);
        addTab("Social", R.drawable.tab_search, UploadVideo.class);

        addTab("Contact Us", R.drawable.tab_home, Contactus.class);
        addTab("Setting", R.drawable.tab_search, DoNotDo.class);




    }

    private void addTab(String labelId, int drawableId, Class<?> c) {
        TabHost tabHost = getTabHost();
        Intent intent = new Intent(this, c);
        TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId);

        View tabIndicator = LayoutInflater.from(this).inflate(
                R.layout.tab_indicator, getTabWidget(), false);
        TextView title = (TextView) tabIndicator.findViewById(R.id.title);
        title.setText(labelId);
        ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
        icon.setImageResource(drawableId);

        spec.setIndicator(tabIndicator);
        spec.setContent(intent);
        tabHost.addTab(spec);
    }
}

here is xml

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:background="#ffffff"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1" />

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="2dp"
            android:layout_weight="0" />

    </LinearLayout>

</TabHost>
于 2015-01-06T12:48:29.423 回答
1

一个想法是创建BaseActivity,其中包括您在整个应用程序中喜欢的一般设计。在其他活动中,扩展BaseActivity。您还可以在一些不需要显示按钮的活动中扩展Activity类,例如LoginActivity

于 2015-01-06T11:09:37.540 回答