① android api19以下怎么修改状态栏颜色
第一步:导入支持包到工程[^code]
说明:这个支持包是我从github上的开源项目上脱下来的,就是一个java文件,方便我们自己修改。
第二步:修改主题文件
首先你需要在你工程的res目录下新建个Values-V19的包,然后再建个styles.xml,如下所示:
<resources>
<!--
Base application theme for API 19+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 19+ devices.
-->
<style name="ActionBarTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowTranslucentNavigation" >true</item>
<item name="android:windowTranslucentStatus">true</item>
<!-- toolbar(actionbar)颜色 -->
<item name="colorPrimary">#673AB7</item>
<!-- 状态栏颜色 -->
<item name="colorPrimaryDark">#512DA8</item>
</style>
</resources>
② android的toolbar的返回键有必要存在吗
有必要,当你用右手手持大屏幕手机时单手很难碰到左上角的返回按钮,而且安卓还有一个功能叫做长按返回键强制结束应用”
③ android的toolbar的返回键有必要存在吗
其实,对于安卓来说,真的没必要,因为android机都会有实体返回键的。但是,很多设计者会追求和IOS的统一,或者说,懒的再专门给Android开发一套UI,所以就造成了Android应用的toolbar上基本都有返回键。这也就是为什么google的Material Design没有普及的大部分原因。其实google推荐的toolbar是没有返回键的,这点从新建项目时的模板上可以看出来。
④ 如何用android studio编写toolbar
目前toolbar,有官方的组件可以使用,可以设置菜单、悬浮的菜单等等功能,还可以设置颜色文字
⑤ android中怎样将toolbar扩展到状态栏
有一个思路,使用正常的Toolbar,把页面的布局设置为Overly,这样页面内容就会顶到屏幕最顶,toolbar和statusbar的颜色都设置为透明。如果要给toolbar加背景,可以在真正的内容布局那块添加一个子view叠加在toolbar和startbar下面,大功告成=_=
⑥ android v7包里的Toolbar,怎么定制图标,字体居中的效果
1.文字的话仅可设置为底部居中或中部居右,在TextAlignment属性中设置,值分别为0和1,没有中部居中,至于为什么在下面说明了;
2.不能改字体,不能改颜色。
另外,强烈建议用Toolbar工具栏设计时使用图标来代替文字,或者图标和文字都有,相信用过Windows我的电脑工具栏自定义的都知道,标签可选为“显示文本标签”(就是显示在图标下面)或“选择性地文本置于右侧”这就是第1点为什么只能选2个值的原因了。
至于怎么用图标,再拖一个ImageList控件进窗体,设计时插入所有要用到的图标,记住每个图标的索引编号,在Toolbar控件中设置按钮图像为索引编号,0为没有图标。
编程时实现采用
Toolbar1.Buttons(1).Image = 索引
⑦ 如何设置android 5.0主题,状态栏,toolbar颜色设定
关键图:
关键代码:
res->values->styles
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
⑧ Android关于Toolbar标题栏图标比较大的问题
颜色较灰,我想是图片的问题。推荐你一个网站,可以自由调整图标的颜色,就不会出现这个问题了。网页链接
至于标题栏图标的显示问题,首先需要ImageView控件,根据Toolbar的宽度设置好控件的大小,然后设置ImageView的对齐方式,之后的关键是实时调整控件的padding和layout_margin属性。具体可参照下面:
<ImageView
android:id="@+id/toolbarButton"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="end"
android:layout_marginTop="13dp"
android:paddingBottom="5dp"
android:paddingEnd="10dp"
android:paddingTop="15dp" />
欢迎采纳,沟通呀!也在学习Android编程,哈哈
⑨ android的toolbar的返回键有必要存在吗
其实,对于安卓来说,真的没必要,因为android机都会有实体返回键的。
但是,很多设计者会追求和IOS的统一,或者说,懒的再专门给Android开发一套UI,所以就造成了Android应用的toolbar上基本都有返回键。
这也就是为什么google的Material Design没有普及的大部分原因。
其实google推荐的toolbar是没有返回键的,这点从新建项目时的模板上可以看出来。
⑩ 如何设置toolbar里的DrawerLayout按钮的颜色
首先使用 Toolbar 来代替ActionBar
,这样我们就能够把ActionBar嵌入到我们的View体系中,然后我们"禁用"系统的status bar,由 DrawerLayout
来处理status bar,最后抽屉部分往上移,或者裁剪掉status bar那一部分。
控制Status bar
在你的values-v21里面添加新的主题,并设置一下属性:
values-v21/themes.xml
<style name="AppTheme">
<item name="android:">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
这里解释一下:
,将它设置为true,系统将在你的window里面绘制status
bar,默认为 TRUE
,之所以要写出来是因为你的theme有可能是继承过来的,确保为true。(在这里小插曲一下,因调试时,总以为注释了这段代码就以为是false,程
序员思维害苦了我。另外从命名来看,Android把它称为system bar,可能是为了与能被我们处理的status bar区分开而做的改变。)
statusBarColor 设置为透明是因为我们不再需要系统的status bar,因为我们无法控制它的位置,后面我们将交由 DrawerLayout 来处理。
使用DrawerLayout
首先,你的布局文件应该是和这个类似的:
<android.support.v4.widget.DrawerLayout
xmlns:android="url"
android:id="@+id/my_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<!-- Your normal content view -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- We use a Toolbar so that our drawer can be displayed
in front of the action bar -->
<android.support.v7.widget.Toolbar
android:id="@+id/my_awesome_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
<!-- The rest of your content view -->
</LinearLayout>
<!-- The navigation drawer -->
<ScrimInsetsFrameLayout xmlns:android="rul"
xmlns:app="url"
android:layout_width="304dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="@android:color/white"
android:elevation="10dp"
android:fitsSystemWindows="true"
app:insetForeground="#4000">
<!-- Your drawer content -->
</ScrimInsetsFrameLayout>
</android.support.v4.widget.DrawerLayout>
在这里布局里面我们用到了一个的开源类 ScrimInsetsFrameLayout ,它的主要作用就是利用 fitsSystemWindows
的回调方法 fitSystemWindows(Rect insets) 来获取status bar的大小,然后调整画布已达到去掉status
bar的效果,所以我们需要在ScrimInsetsFrameLayout 下设置 fitsSystemWindows
为true。当然你也可以不使用这个类,而改用 layout_marginTop 属性来达到效果。
insetForeground 这个属性是ScrimInsetsFrameLayout自带的,表示插入区域的前景色,我们设置为带透明的黑色#4000。别忘了使用这个属性需要添加如下代码到attrs.xml里:
values/attrs.xml
<declare-styleable name="ScrimInsetsView">
<attr name="insetForeground" format="reference|color" />
</declare-styleable>
自此,我们已经实现了将DrawerLayout抽屉的那一部分显示在 Toolbar 和systembar(为了和下面的status
bar区分,我们称为system bar)之间了,可是system bar的颜色被我们设置了透明,所以我们接下来要改变status
bar的颜色。
改变Status bar的颜色
你可能已经注意到刚才的布局里面 DrawerLayout 的 fitsSystemWindows 属性设置了为true,这是因为我们要在代码里面使用了 DrawerLayout 设置status bar颜色的方法:
// 在这里我们获取了主题暗色,并设置了status bar的颜色
TypedValue typedValue = new TypedValue();
getTheme().resolveAttribute(R.attr.colorPrimaryDark, typedValue, true);
int color = typedValue.data;
// 注意setStatusBarBackgroundColor方法需要你将fitsSystemWindows设置为true才会生效
DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.my_drawer_layout);
drawerLayout.setStatusBarBackgroundColor(color);
使用ToolBar来代替ActionBar
在代码里面这样设置:
Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);