① 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);