zoukankan      html  css  js  c++  java
  • android actionbar标题栏

    在android的actionBar中,actionBar的视图是固定的,左边是程序的图标和title,右边是添加的menuItem,如果想要定制actionbar中的view就要自定义视图。

    首先要定义actionbar的xml

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:id="@+id/layout01"
        >
        
    <ImageButton android:id="@+id/left"
               android:layout_width="wrap_content"
               android:layout_height="fill_parent"
                android:background="@android:color/transparent"
               android:src="@drawable/show_left"
               android:layout_gravity="left|center_vertical"
               android:paddingLeft="8dip"
               android:clickable="true"/>   
               
    <TextView android:id="@+id/tv"
              android:background="@android:color/transparent"
              android:layout_width="wrap_content"
              android:layout_height="match_parent"
              android:text="首页"
              android:textColor="@android:color/white"
              android:textSize="18dip"
              android:paddingTop="2dip"
              android:layout_gravity="center"/>   
              
    <ImageButton android:id="@+id/more"
               android:layout_width="wrap_content"
               android:layout_height="fill_parent"
               android:background="@android:color/transparent"
               android:src="@drawable/cross"
               android:paddingRight="8dip"
               android:clickable="true"
               android:layout_gravity="right|center_vertical"/>  
    </FrameLayout>

    然后在onCreateMenuItem设置actionBar的样式,一定要设 置 actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM)和 actionBar.setDisplayShowCustomEnabled(true);

    public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            
            actionBar=this.getActionBar();       
            ActionBar.LayoutParams params=new ActionBar.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT,Gravity.CENTER );
            View view=LayoutInflater.from(this).inflate(R.layout.actionbar, null);
            actionBar.setCustomView(view,params);
            actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
            actionBar.setDisplayShowCustomEnabled(true);
            
           ImageButton more=(ImageButton) this.findViewById(R.id.more);
           ImageButton left=(ImageButton) this.findViewById(R.id.left);
           left.setOnTouchListener(new MyTouchListener());
           more.setOnTouchListener(new MyTouchListener());
            return true;
            
        }
    
    }
    class MyTouchListener implements OnTouchListener
    {
    
        @Override
        public boolean onTouch(View view, MotionEvent arg1) {
             if(arg1.getAction()==MotionEvent.ACTION_DOWN)
               {
                    view.setBackgroundColor(Color.LTGRAY);
               }
               if(arg1.getAction()==MotionEvent.ACTION_UP)
               {
                    view.setBackgroundColor(Color.TRANSPARENT);
               }
             return true;
        }
  • 相关阅读:
    PAIP.paip.手机离线ROOT过程总结
    paip.程序设计扫号器跑号器结果分类设计
    PAIP.测试硬盘的成色以及速率
    paip.httpd.conf 是空的.txt
    paip.c#.nett 系统托盘动态图标闪烁图标
    paip.验证码识别反馈法提高识别率
    paip.提升用户体验找回密码的设
    paip.sql2008 客户端软件绿色版V319
    提升用户体验自动邮编提示与验证地址
    PAIP.提升性能---LISTBOX加载30万大数据量终结方案
  • 原文地址:https://www.cnblogs.com/zhujiabin/p/4250419.html
Copyright © 2011-2022 走看看