zoukankan      html  css  js  c++  java
  • 指令汇C电子市场开发(一) ActionBar的使用

    前话:

    在学习开发谷歌电子市场的的时候,我换了一款比较高大上的模拟器——genymotion,首先去genymotion的官网注册下载,然后安装。感觉这款模拟器运行挺快的,哈哈,而且可以直接把应用拖进去安装,还可以拖到尺寸,比安卓原生的模拟器好用多啦!原谅我现在才知道大笑


    一、ActionBar的使用

    我们可以参考安卓官网的文档进行开发,主要分为ActionBar的搜索、按钮返回处理、添加tab标签等操作。

    添加ActionBar:

    清单文件中:<activity android:theme="@style/Theme.AppCompat.Light" ... >

    1、搜索的实现步骤:

    在menu中添加

    <menu xmlns:android="http://schemas.android.com/apk/res/android" >
        xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
        <!-- Search, should appear as action button -->
        <item android:id="@+id/action_search"
              android:icon="@drawable/ic_action_search"
              android:title="@string/action_search"
              yourapp:showAsAction="ifRoom"  />
    </menu>
    MainActivity.java中

                     @Override
    		public boolean onCreateOptionsMenu(Menu menu) {
    			getMenuInflater().inflate(R.menu.activity_main, menu);
    			SearchView searchView = (SearchView) menu.findItem(R.id.action_search)
    					.getActionView();
    			searchView.setOnQueryTextListener(this);//  搜索的监听
    			return true;
    		}
     
    		  // 当搜索提交的时候
    		@Override
    		public boolean onQueryTextSubmit(String query) {
    			Toast.makeText(getApplicationContext(), query, 0).show();
    			return true;
    		}
    		// 当搜索的文本发生变化
    		@Override
    		public boolean onQueryTextChange(String newText) {
    			//Toast.makeText(getApplicationContext(), newText, 0).show();
    			return true;
    		}

    2、返回按钮的处理

    1 	
     		
    		ActionBar actionBar = getSupportActionBar();
    		actionBar.setDisplayHomeAsUpEnabled(true);
    2   	
    		  
    		 <activity  android:name=".DetailActivity"
                android:label="@string/app_detail"
                 android:parentActivityName="com.itheima.googleplay.MainActivity"
                >
                 <!-- Parent activity meta-data to support 4.0 and lower -->
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.itheima.googleplay.MainActivity" />
            </activity>

    3、Tab标签

    首先在Drawable 目录下 写了一个标签的状态选择器

    actionbar_tab_indicator.xml

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
    <!-- STATES WHEN BUTTON IS NOT PRESSED -->
    
        <!-- Non focused states -->
        <item android:state_focused="false" android:state_selected="false"
              android:state_pressed="false"
              android:drawable="@drawable/tab_unselected" />
        <item android:state_focused="false" android:state_selected="true"
              android:state_pressed="false"
              android:drawable="@drawable/tab_selected" />
    
        <!-- Focused states (such as when focused with a d-pad or mouse hover) -->
        <item android:state_focused="true" android:state_selected="false"
              android:state_pressed="false"
              android:drawable="@drawable/tab_unselected_focused" />
        <item android:state_focused="true" android:state_selected="true"
              android:state_pressed="false"
              android:drawable="@drawable/tab_selected_focused" />
    
    <!-- STATES WHEN BUTTON IS PRESSED -->
    
        <!-- Non focused states -->
        <item android:state_focused="false" android:state_selected="false"
              android:state_pressed="true"
              android:drawable="@drawable/tab_unselected_pressed" />
        <item android:state_focused="false" android:state_selected="true"
            android:state_pressed="true"
            android:drawable="@drawable/tab_selected_pressed" />
    
        <!-- Focused states (such as when focused with a d-pad or mouse hover) -->
        <item android:state_focused="true" android:state_selected="false"
              android:state_pressed="true"
              android:drawable="@drawable/tab_unselected_pressed" />
        <item android:state_focused="true" android:state_selected="true"
              android:state_pressed="true"
              android:drawable="@drawable/tab_selected_pressed" />
    </selector>

    btn_bg.xml

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android"  android:enterFadeDuration="200">
        <item  android:state_pressed="true" android:drawable="@drawable/btn_pressed"></item>
        <item  android:drawable="@drawable/btn_normal"></item>
    
    </selector>

    在代码里添加标签


    ActionBar actionBar = getSupportActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    Tab tab1=actionBar.newTab().setText("首页").setTabListener(new MyTabListener());
    actionBar.addTab(tab1);





  • 相关阅读:
    使用事物码SAT检测SAP CRM中间件的传输性能
    显示SAP CRM Product hierarchy的一个小工具
    如何使用SAP CRM中间件从ERP往CRM下载Service Master
    SAP CL_CRM_BOL_ENTITY单元测试方法
    SAP CRM错误消息 Specify at least one number for the business partner
    Java注解@Autowired的工作原理
    Spring里component-scan的工作原理
    Spring框架里解析配置文件的准确位置
    SAP CRM状态字段下拉列表里数据的填充原理
    用户自定义协议client/server代码示例
  • 原文地址:https://www.cnblogs.com/sdksdk0/p/5585116.html
Copyright © 2011-2022 走看看