简体   繁体   English

如何在 android 中制作 iphone 风格的菜单栏

[英]How to make an iphone style menu bar in android

I'm attempting to port an iphone app to the android.我正在尝试将 iphone 应用程序移植到 android。 Inside of the app there is a static bar with five buttons that acts like a menu bar (ie clicking one button will bring up a corresponding page) This bar does not go away and it should light up depending on what button is pressed.应用程序内部有一个 static 栏,带有五个按钮,其作用类似于菜单栏(即单击一个按钮将打开相应的页面)此栏不会 go 消失,它应该根据按下的按钮亮起。 I don't know how to get started on this and was wondering if anyone could give me some help.我不知道如何开始,并且想知道是否有人可以给我一些帮助。 Here are the buttons.这是按钮。 Thank you谢谢纽扣

In my opinion, this is not a good idea to copy an iPhone app.在我看来,复制 iPhone 应用程序并不是一个好主意。 User interfaces (and therefore user behaviours) are totally different and iPhone and Android devices.用户界面(因此用户行为)与 iPhone 和 Android 设备完全不同。 Ask yourself "is it the right way to do it on Android?"问问自己“在 Android 上这样做是否正确?” If you are not sure, just don't do it.如果您不确定,请不要这样做。 But do like other developers on Android do.但是像 Android 上的其他开发人员一样。

You can follow this tutorial to start http://developer.android.com/resources/tutorials/views/hello-tabwidget.html then (only when you understand it) try something like this for each of your tabs:您可以按照本教程开始http://developer.android.com/resources/tutorials/views/hello-tabwidget.html然后(仅当您的每个选项卡理解它时)

// Initialize a TabSpec for each tab and add it to the TabHost

spec = mTabHost.newTabSpec("Name of tab");
v = View.inflate(this, R.layout.tabbar_tabview, null);
((ImageView)v.findViewById(R.id.tabbar_tabview_img)).setBackgroundResource(R.drawable.ic_tab_expenses);
((TextView)v.findViewById(R.id.tabbar_tabview_text)).setText(R.string.general_tab_expenses);
spec.setIndicator(v);
spec.setContent(intent);
mTabHost.addTab(spec);

This is the content of my "tabbar_tabview.xml":这是我的“tabbar_tabview.xml”的内容:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:padding="0dp"
    android:layout_height="fill_parent" android:layout_width="fill_parent"
        android:background="@drawable/tabview_background">

    <ImageView android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/tabbar_tabview_img"
        android:layout_gravity="center" android:layout_marginTop="5dp"></ImageView>

    <TextView  android:id="@+id/tabbar_tabview_text" android:layout_width="wrap_content"
        android:gravity="center" android:layout_height="wrap_content" android:textSize="13dp" android:layout_marginBottom="5dp"
        android:layout_gravity="center" android:textColor="@drawable/tabview_text_color"></TextView>

</LinearLayout> 

And this is the content of my tabview_background.xml:这是我的 tabview_background.xml 的内容:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_selected="true">
        <shape>
             ### I defined a shape here ###
        </shape>
    </item>

    <item>
        <shape>
             ### I defined a shape here ###
        </shape>
    </item>
</selector>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM