zoukankan      html  css  js  c++  java
  • android实现底部菜单栏

    android程序,许多时候需要菜单栏显示在底部或顶部,但是没有很好的组建供程序员调用,过自定义了一个视图,用来实现底部菜单栏,效果如下图:

    实现的主要代码:

     

    @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(R.layout.main);

            linearLayout = (LinearLayout) findViewById(R.id.home);
            linearLayout.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    linearLayout
                            .setBackgroundResource(R.drawable.tab_two_highlight);
                    publish.setBackgroundResource(R.drawable.tab_one_normal);
                    change.setBackgroundResource(R.drawable.tab_one_normal);
                    more.setBackgroundResource(R.drawable.tab_one_normal);
                }
            });
            linearLayout
            .setBackgroundResource(R.drawable.tab_two_highlight);

            publish = (LinearLayout) findViewById(R.id.publish);
            publish.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    publish.setBackgroundResource(R.drawable.tab_two_highlight);
                    linearLayout.setBackgroundResource(R.drawable.tab_one_normal);
                    change.setBackgroundResource(R.drawable.tab_one_normal);
                    more.setBackgroundResource(R.drawable.tab_one_normal);
                }
            });

            change = (LinearLayout) findViewById(R.id.change);
            change.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    change.setBackgroundResource(R.drawable.tab_two_highlight);
                    linearLayout.setBackgroundResource(R.drawable.tab_one_normal);
                    publish.setBackgroundResource(R.drawable.tab_one_normal);
                    more.setBackgroundResource(R.drawable.tab_one_normal);
                }
            });

            more = (LinearLayout) findViewById(R.id.more);
            more.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    more.setBackgroundResource(R.drawable.tab_two_highlight);
                    linearLayout.setBackgroundResource(R.drawable.tab_one_normal);
                    publish.setBackgroundResource(R.drawable.tab_one_normal);
                    change.setBackgroundResource(R.drawable.tab_one_normal);
                }
            });
        }

    配置文件实现:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal" android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical" android:layout_width="80px"
            android:layout_height="wrap_content" android:id="@+id/home"
            android:background="@drawable/tab_one_normal">
            <TextView android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:text="@string/home"
                android:gravity="center" android:paddingTop="29px"
                android:background="@drawable/home" />
        </LinearLayout>
        <ImageView android:layout_width="wrap_content"
                android:layout_height="wrap_content"  android:src="@drawable/line" />
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical" android:layout_width="80px"
            android:layout_height="wrap_content" android:background="@drawable/tab_one_normal"
            android:id="@+id/publish">
            <TextView android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:text="@string/publish"
                android:gravity="center" android:paddingTop="29px"
                 android:background="@drawable/publish" />
        </LinearLayout>
        <ImageView android:layout_width="wrap_content"
                android:layout_height="wrap_content"  android:src="@drawable/line" />
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical" android:layout_width="80px" android:id="@+id/change"
            android:layout_height="wrap_content" android:background="@drawable/tab_one_normal">
            <TextView android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:text="@string/change"
                android:gravity="center" android:paddingTop="29px"
                 android:background="@drawable/change" />
        </LinearLayout>
        <ImageView android:layout_width="wrap_content"
                android:layout_height="wrap_content"  android:src="@drawable/line" />
        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical" android:layout_width="80px" android:id="@+id/more"
            android:layout_height="wrap_content" android:background="@drawable/tab_one_normal">
            <TextView android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:text="@string/more"
                android:gravity="center" android:paddingTop="29px"
                 android:background="@drawable/more" />
        </LinearLayout>
    </LinearLayout>

    源代码见:http://easymorse.googlecode.com/svn/trunk/android.bottom

  • 相关阅读:
    EOS之session的数据获取
    c# 数据库操作之ACCESS
    基础之创建与导出
    dotNET5的MVC页面传值方式总结
    dotNET开发之MVC中Controller返回值类型ActionResult方法总结
    C# 计算农历日期方法(2021版)
    普通邮箱设置客户端授权码并开启stmp服务以及关于QQ邮箱“命令顺序不正确。 服务器响应为:Error: need EHLO and AUTH first !”问题全指导
    13 张图,深入理解 Synchronized
    Springboot 注解大全
    python中的print()函数的学习-1
  • 原文地址:https://www.cnblogs.com/lm3515/p/1983309.html
Copyright © 2011-2022 走看看