zoukankan      html  css  js  c++  java
  • 15 Actionbar的显示和隐藏

    ActionBar

    这里写图片描述

    • 显示隐藏方法:

      • 在布局文件中设置 theme主题

        <?xml version="1.0" encoding="utf-8"?>
        <manifest xmlns:android="http://schemas.android.com/apk/res/android"
            package="com.qf.day15_actionbar_demo1"
            android:versionCode="1"
            android:versionName="1.0" >
        
            <uses-sdk
                android:minSdkVersion="11"
                android:targetSdkVersion="18" />
        
            <!--
            换主题  换不同的action样式
            android:theme="@style/AppTheme"
                 android:theme="@android:style/Theme.Light" 
                 android:theme="@android:style/Theme.Holo"
                   android:theme="@android:style/Theme.Holo.Light"
                     android:theme="@android:style/Theme.Holo.NoActionBar"
            -->
            <application
                android:allowBackup="true"
                android:icon="@drawable/ic_launcher"
                android:label="@string/app_name"
                android:theme="@style/AppTheme"
        
                 >
                <activity
        
                    android:name="com.qf.day15_actionbar_demo1.MainActivity"
                    android:label="@string/app_name" 
                    android:uiOptions="splitActionBarWhenNarrow"
                    >
                    <intent-filter>
                        <action android:name="android.intent.action.MAIN" />
        
                        <category android:name="android.intent.category.LAUNCHER" />
                    </intent-filter>
                </activity>
            </application>
        
        </manifest>
      • 逻辑代码中

        package com.qf.day15_actionbar_demo1;
        
        import android.annotation.SuppressLint;
        import android.app.ActionBar;
        import android.app.Activity;
        import android.os.Bundle;
        import android.view.Menu;
        import android.view.MenuItem;
        import android.view.View;
        import android.view.Window;
        import android.widget.TextView;
        
        public class MainActivity extends Activity {
        
            private ActionBar actionBar;
        
            private TextView tv;
        
            private int tvSize = 10;
            @SuppressLint("NewApi")
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                //方法控制没有标题栏 // 要在setContent之前设置否则直接奔溃 
                //requestWindowFeature(Window.FEATURE_NO_TITLE);
        
                //显示
        //      requestWindowFeature(Window.FEATURE_ACTION_BAR);
                setContentView(R.layout.activity_main);
        
                tv = (TextView) findViewById(R.id.tv);
        
                //获取当前ActionBar
                actionBar = getActionBar();
        
                //应用图标是否能点击    带一个向左的箭头 监听的ID是android.R.id.home
                actionBar.setDisplayHomeAsUpEnabled(true);
                //应用图标是否能点击  不带箭头
                //actionBar.setHomeButtonEnabled(true);
        
                //是否显示应用程序图标
                actionBar.setDisplayShowHomeEnabled(true);
            }
        
            @Override
            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);
                return true;
            }
        
        
            @Override
            public boolean onOptionsItemSelected(MenuItem item) {
                switch (item.getItemId()) {
                case android.R.id.home://应用程序图标的id
        
                    finish();
        
                    break;
                case R.id.action_add:
                    tvSize+=10;
                    tv.setTextSize(tvSize);
                    break;
                case R.id.action_call:
                    tv.setText("拨打电话中....");
                    break;
                case R.id.action_camera:
                    tv.append("
        "+"美颜拍照");
                    break;
                case R.id.action_delete:
                    tv.setText("");
                    break;
        
                default:
                    break;
                }
                return super.onOptionsItemSelected(item);
            }
        
        
            public void MyClick(View v){
                //判断actionBar是否正在展示  
                if(actionBar.isShowing()){
                    actionBar.hide();//隐藏
                }else{
                    actionBar.show();//显示
                }
            }
        
        }
        
  • 相关阅读:
    [SIP]SIP之穿越NAT 幻灯片
    此Slashdotcn模仿彼Slashdot
    [RTC]如何得到Interop.RTCCore.dll
    androidmanifest.xml权限中文说明
    Android Service学习之本地服务
    从问题看本质:socket到底是什么?
    Android小项目之服务【Service】
    listen函数
    Android开发资源完全汇总
    ANDROID基础知识普
  • 原文地址:https://www.cnblogs.com/muyuge/p/6152252.html
Copyright © 2011-2022 走看看