纹身网站设计,新都网站开发,网页设计说明万能模板,wordpress安装不成功一、ToolBar 1、概述 Google在2015的IO大会上发布了系列的Material Design#xff08;材料设计语言#xff09;风格的控件。其中ToolBar是替代ActionBar的控件。由于ActionBar在各个安卓版本和定制Rom中的效果表现不一#xff0c;导致严重的碎片化问题#xff0c;ToolBar应… 一、ToolBar 1、概述 Google在2015的IO大会上发布了系列的Material Design材料设计语言风格的控件。其中ToolBar是替代ActionBar的控件。由于ActionBar在各个安卓版本和定制Rom中的效果表现不一导致严重的碎片化问题ToolBar应运而生。 与ActionBar区别显示效果跟ActionBar并没有区别。优点自定义视图的操作更加简单状态栏的颜色可以调Android 4.4以上。 2、使用方法 2.1 导包(配置Gradle) compile com.android.support:appcompat-v7:22.0.0 2.2 在AndroidManifest.xml设置此Activity的主题 item namewindowActionBarfalse/itemitem namewindowNoTitletrue/item 注意务必将ActionBar消除否则Activity将会崩溃 2.3 重定义主题(颜色等信息) Android 4.4及以上在values文件夹中新建values-v19.xml内容如下 resources
style nameAppTheme parentTheme.AppCompat.Light.NoActionBaritem namewindowActionBarfalse/itemitem nameandroid:windowNoTitletrue/item!--Toolbar颜色--item namecolorPrimaryandroid:color/holo_blue_bright/item!-- 状态栏颜色 --item namecolorPrimaryDarkandroid:color/holo_blue_bright/itemitem nameandroid:windowTranslucentNavigationtrue/itemitem nameandroid:windowTranslucentStatustrue/item/style/resources Android 4.4以下
resourcesstyle nameAppTheme parentTheme.AppCompat.Light.NoActionBaritem namewindowActionBarfalse/itemitem nameandroid:windowNoTitletrue/item!--Toolbar颜色--item namecolorPrimarycolor/Indigo_colorPrimary/item/style/resources 2.4 ToolBarxml文件中定义 ?xml version1.0 encodingutf-8?android.support.v7.widget.Toolbar xmlns:androidhttp://schemas.android.com/apk/res/androidandroid:idid/toolbarandroid:layout_heightwrap_contentandroid:layout_widthmatch_parentandroid:background?attr/colorPrimary //设置toolbar的背景颜色android:minHeight?android:attr/actionBarSize !-- 最小高度 --/android.support.v7.widget.Toolbar android:fitsSystemWindowstrue 防止ToolBar与StatusBar融合2.5 java代码中实现 private Toolbar mToolbar;
private WebFragment mWebFragment;
private long mBeforeTime;Override
protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);if (Build.VERSION.SDK_INT Build.VERSION_CODES.KITKAT) { //版本检测SystemBarTintManager tintManager new SystemBarTintManager(this);mToolbar (Toolbar) findViewById(R.id.toolbar);tintManager.setStatusBarTintEnabled(true); //更改状态栏设置setSupportActionBar(mToolbar); //将ToolBar设置成ActionBartintManager.setStatusBarTintResource(android.R.color.holo_blue_bright);}getSupportActionBar().setHomeButtonEnabled(true); //设置返回键可用getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} 2.6 参考文章 http://blog.csdn.net/qq284565035/article/details/47086439http://www.itstrike.cn/Question/9ae75549-b316-4844-938e-c22c0f4e6692.html 二、ActionBar 1、概述 ActionBar位于Activity的顶部可用来显示activity的标题、Icon、Actions和一些用于交互的View。它也可被用于应用的导航。ActionBar 是在Android 3.0(API 11中加入到SDK中的想在低版本中使用ActionBar有两种选择使用http://actionbarsherlock.com 或使用Support Library v7。 图示 其中[1]是ActionBar的图标[2]是两个action按钮[3]是overflow按钮 2、使用方法 2.1低版本API11 开发API11以下的程序首先必须在AndroidManifest.xml中指定Application或Activity的theme是Theme.Holo或其子类否则将无法使用ActionBar。 2.1创建Actions 类似于Menu即可在java代码中添加也可在xml文件中添加。下面贴上xml代码 menu xmlns:androidhttp://schemas.android.com/apk/res/android itemandroid:idid/action_refreshandroid:orderInCategory100android:showAsActionalwaysandroid:icondrawable/ic_action_refreshandroid:titleRefresh/itemandroid:idid/action_settingsandroid:titleSettings/item
/menu 说明 showAsAction属性定义每个Action是如何显示的 always表示永远显示在ActionBar中如果屏幕空间不够则无法显示ifRoom表示屏幕空间够的情况下显示在ActionBar中不够的话就显示在overflow中never则表示永远显示在overflow中 在java代码中,通过重写onCreateOptionsMenu以使用上面的menu Override
public boolean onCreateOptionsMenu(Menu menu) {MenuInflater inflater getMenuInflater();inflater.inflate(R.menu.mainmenu, menu);return true;
} 2.2 Action的按钮交互 如果一个Action被单击对于activity中的onOptionsItemSelected()将被调用。 Override
public boolean onOptionsItemSelected(MenuItem item) {switch (item.getItemId()) {// action with ID action_refresh was selectedcase R.id.action_refresh:Toast.makeText(this, Refresh selected, Toast.LENGTH_SHORT).show();break;// action with ID action_settings was selectedcase R.id.action_settings:Toast.makeText(this, Settings selected, Toast.LENG).show();break;default:break;}return true;
} 说明 onCreateOptionsMenu()只会被调用一次。若想改变Menu可以调用invalidateOptionsMenu()这会使onCreateOptionsMenu()将会再次被调用。 3、自定义ActionBar 3.1隐藏与显现 ActionBar actionBar getActionBar();
actionBar.hide();
// more stuff here...
actionBar.show(); 3.2改变title ActionBar actionBar getActionBar();
actionBar.setSubtitle(mytest);
actionBar.setTitle(vogella.com); 3.3隐藏导航 getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); 3.4使用全屏模式 对于Android 4.4 (API 19)应用程序可以使用全屏模式代码如下 // This method hides the system bars and resize the contentprivate void hideSystemUI() {getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar| View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar// remove the following flag for version API 19| View.SYSTEM_UI_FLAG_IMMERSIVE);} 3.4使用Split action bar 启用split action bar可在 AndroidManifest.xml中定义android:uiOptionsSplitActionBarWhenNarrow 参阅http://blog.csdn.net/lsdmx2016/article/details/17415911 4、在Fragment中给action bar添加action 在onCreate()中调用 setHasOptionsMenu(true)。Android Framework会调用Fragement中的onCreateOptionsMenu()来向Activity的Menu中添加item。 5、动态设置action bar 5.1自定义View actionBar.setCustomView(R.layout.actionbar_view);EditText search (EditText) actionBar.getCustomView().findViewById(R.id.searchfield); 5.2Action View示例见参考文章 Action View控件可以替换Action bar的Action按钮图标。可以利用这个特点将某个Action项替换成一个ProgressBar。可通过android:actionLayout或android:actionViewClass来定义一个布局文件或Widg来作为Action的action view。 5.3Action Provider示例见参考文章 Action Provider提供了在单个组件里提供多种交互方式的方法。它可以用来创建action view动态弹出子menu处理action调用事件。基类为ActionProvider 目前Android平台提供两种action providerMediaRouteActionProvider和ShareActionProvider。 下面以一个例子计算ShareActionProvider的用法。使用这个action provider可以让程序从注册了Intent.ACTION_SEND的Intent中获取。 6、使用程序图标导航 6.1使用程序图标作为home icon Action Bar的左侧图标称为home icon可为这个图标设置一个Action。推荐做法是当按了这个图标返回到Home Activity中。 actionBar.setHomeButtonEnabled(true);//或者使用actionBar.setDisplayHomeAsUpEnabled(true); 在onOptionsMenuItemSelected() 中使用android.R.id.home并启用actionbar的HomeIconcase android.R.id.home: 参考文章 1、http://blog.csdn.net/bigconvience/article/details/28886241 特别说明 1、AndroidStudio中按照默认的Activity启动时不显示ActionBar的问题 在Eclipse新建一个MainActivity extends Activity时能够正常显示ActionBar如图 但在AS中extends Activity不显示ActionBar如图 但在AS中extends ActionBarActivity能够正常显示ActionBar但是会显示该类过时 推荐使用extends AppCompatActivity 同样的代码在Eclipseh和Android Studio中会出现较大差异需要区别对待。AppCompatActivity是为了兼容性考虑造成这种差异的原因是主题的问题 在主题方面还有很多不懂今后加强学习 ToolBar的使用 ActionBar ActionBar 是android 3.0的推出的当时Google 想要逐渐改善过去 android 纷乱的界面设计希望让终端使用者尽可能在 android 手机有个一致的操作体验。ActionBar 过去最多人使用的两大套件就是 ActionBarSherlock 以及官方提供在 support library v 7 里的 AppCompat。 Action bar被包含在所有的使用Theme.Hole主题的Activity或者是这些Activity的子类中。 删除actionbar 如果不想用ActionBar那么只要在theme主题后面 .NoActionBar, 就可以了。 由于现在用的不多了所以就一带而过了。 Toolbar Toolbar 是android 5.0的推出的放在了v7包中作为控件它是为了取代actionbar而产生的意味着官方在某些程度上认为 ActionBar 限制了 android app 的开发与设计的弹性而在 material design 也对之做了名称的定义App bar。 简单使用 布局 android.support.v7.widget.Toolbarandroid:idid/toolbarandroid:layout_widthmatch_parentandroid:layout_height?attr/actionBarSizeandroid:background?attr/colorPrimaryapp:popupThemestyle/ThemeOverlay.AppCompat.Lightapp:layout_scrollFlagsscroll|enterAlways/ 代码 Toolbar toolbar (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar); setSupportActionBar 设定Toolbar即能取代原本的 actionbar 了 截图说明一下 toolbar.png 其他详细的使用可以看推荐的下面文章, 已经写的很好了: androidToolBar详解手把手教程 Theme的背景颜色等的详细如下 使用 colorPrimary 来给你的 App Bar 上色 StatusBar TitleBar、ActionBar、ToolBar之间的关系 StatusBar,也就是状态栏它处于屏幕的最顶部正常情况下它是显示的它和TitleBar和ActionBar之间没有直接的关系。 1.如果想在应用中隐藏他的话可以通过下面的方式 2.如果想获取它的高度通过以下方式 TitleBar也就是标题栏,它紧挨状态栏的下面正常情况下它的布局和主题样式都是使用系统定义好的且默认情况下只显示图标和文本。 1.如果你想改变它的布局和主题样式可以通过下面的方式: 注意的是1.上面代码的执行顺序不能变2.通过上面的代码不能设置标题栏的大小和背景但是可以自定义主题样式 2.如果想获取它的高度可以通过以下方式 int contentTop getWindow().findViewById(Window.ID_ANDROID_CONTENT).getTop(); //statusBarHeight是上面状态栏的高度 int titleBarHeight contentTop - statusBarHeight; ActionBar也就是操作栏它是Android3.0以后引入SDK的通过它去取代之前标题栏它和标题栏一样紧挨状态栏的下面关于他的详情ActionBar的基本用法
文章转载自: http://www.morning.rshs.cn.gov.cn.rshs.cn http://www.morning.tkrdg.cn.gov.cn.tkrdg.cn http://www.morning.yrhpg.cn.gov.cn.yrhpg.cn http://www.morning.yrdn.cn.gov.cn.yrdn.cn http://www.morning.mqzcn.cn.gov.cn.mqzcn.cn http://www.morning.sbrxm.cn.gov.cn.sbrxm.cn http://www.morning.yrddl.cn.gov.cn.yrddl.cn http://www.morning.jpmcb.cn.gov.cn.jpmcb.cn http://www.morning.cjnfb.cn.gov.cn.cjnfb.cn http://www.morning.btcgq.cn.gov.cn.btcgq.cn http://www.morning.mrfr.cn.gov.cn.mrfr.cn http://www.morning.rhqn.cn.gov.cn.rhqn.cn http://www.morning.smkxm.cn.gov.cn.smkxm.cn http://www.morning.qhkx.cn.gov.cn.qhkx.cn http://www.morning.yhyqg.cn.gov.cn.yhyqg.cn http://www.morning.xdnhw.cn.gov.cn.xdnhw.cn http://www.morning.kqpsj.cn.gov.cn.kqpsj.cn http://www.morning.c7500.cn.gov.cn.c7500.cn http://www.morning.gwmny.cn.gov.cn.gwmny.cn http://www.morning.kxnnh.cn.gov.cn.kxnnh.cn http://www.morning.bpmdn.cn.gov.cn.bpmdn.cn http://www.morning.wyrkp.cn.gov.cn.wyrkp.cn http://www.morning.psxcr.cn.gov.cn.psxcr.cn http://www.morning.ptslx.cn.gov.cn.ptslx.cn http://www.morning.cwtrl.cn.gov.cn.cwtrl.cn http://www.morning.pxjp.cn.gov.cn.pxjp.cn http://www.morning.cjnfb.cn.gov.cn.cjnfb.cn http://www.morning.lqtwb.cn.gov.cn.lqtwb.cn http://www.morning.jfymz.cn.gov.cn.jfymz.cn http://www.morning.rlfr.cn.gov.cn.rlfr.cn http://www.morning.mfxcg.cn.gov.cn.mfxcg.cn http://www.morning.deupp.com.gov.cn.deupp.com http://www.morning.xhlpn.cn.gov.cn.xhlpn.cn http://www.morning.rxnxl.cn.gov.cn.rxnxl.cn http://www.morning.crxdn.cn.gov.cn.crxdn.cn http://www.morning.mzhgf.cn.gov.cn.mzhgf.cn http://www.morning.rknjx.cn.gov.cn.rknjx.cn http://www.morning.wsnjn.cn.gov.cn.wsnjn.cn http://www.morning.yfstt.cn.gov.cn.yfstt.cn http://www.morning.nhbhc.cn.gov.cn.nhbhc.cn http://www.morning.qwlml.cn.gov.cn.qwlml.cn http://www.morning.bfgbz.cn.gov.cn.bfgbz.cn http://www.morning.jqbpn.cn.gov.cn.jqbpn.cn http://www.morning.lmfxq.cn.gov.cn.lmfxq.cn http://www.morning.bfybb.cn.gov.cn.bfybb.cn http://www.morning.pnbls.cn.gov.cn.pnbls.cn http://www.morning.tgts.cn.gov.cn.tgts.cn http://www.morning.qzzmc.cn.gov.cn.qzzmc.cn http://www.morning.jwfkk.cn.gov.cn.jwfkk.cn http://www.morning.xkqjw.cn.gov.cn.xkqjw.cn http://www.morning.yknsr.cn.gov.cn.yknsr.cn http://www.morning.qyxnf.cn.gov.cn.qyxnf.cn http://www.morning.jqbpn.cn.gov.cn.jqbpn.cn http://www.morning.zxdhp.cn.gov.cn.zxdhp.cn http://www.morning.pphgl.cn.gov.cn.pphgl.cn http://www.morning.guangda11.cn.gov.cn.guangda11.cn http://www.morning.lmjkn.cn.gov.cn.lmjkn.cn http://www.morning.knmby.cn.gov.cn.knmby.cn http://www.morning.tphrx.cn.gov.cn.tphrx.cn http://www.morning.pghry.cn.gov.cn.pghry.cn http://www.morning.zxdhp.cn.gov.cn.zxdhp.cn http://www.morning.hnpkr.cn.gov.cn.hnpkr.cn http://www.morning.kxqpm.cn.gov.cn.kxqpm.cn http://www.morning.mftzm.cn.gov.cn.mftzm.cn http://www.morning.sjjtz.cn.gov.cn.sjjtz.cn http://www.morning.chfxz.cn.gov.cn.chfxz.cn http://www.morning.tphjl.cn.gov.cn.tphjl.cn http://www.morning.zxqyd.cn.gov.cn.zxqyd.cn http://www.morning.tldhq.cn.gov.cn.tldhq.cn http://www.morning.zlnf.cn.gov.cn.zlnf.cn http://www.morning.plcyq.cn.gov.cn.plcyq.cn http://www.morning.rgsgk.cn.gov.cn.rgsgk.cn http://www.morning.kpcdc.cn.gov.cn.kpcdc.cn http://www.morning.qbwtb.cn.gov.cn.qbwtb.cn http://www.morning.lphtm.cn.gov.cn.lphtm.cn http://www.morning.yltyz.cn.gov.cn.yltyz.cn http://www.morning.jllnh.cn.gov.cn.jllnh.cn http://www.morning.kpwcx.cn.gov.cn.kpwcx.cn http://www.morning.ktsth.cn.gov.cn.ktsth.cn http://www.morning.sgbss.cn.gov.cn.sgbss.cn