① android studio中toolbar怎麼出現自己的應用圖標
一般在手上面的東西是不能刪除的,除非是你i自己後期安裝上去的,否則不要隨意的刪除,尤其是文件類的東西,那麼關於手機軟體的話,你可以將手機解鎖之後再刪除。。。。關於手機解鎖的問題,可以到安趣找答案的。。。非常簡單的哦。。。
② android v7包里的Toolbar,怎麼定製圖標,字體居中的效果
1.文字的話僅可設置為底部居中或中部居右,在TextAlignment屬性中設置,值分別為0和1,沒有中部居中,至於為什麼在下面說明了;
2.不能改字體,不能改顏色。
另外,強烈建議用Toolbar工具欄設計時使用圖標來代替文字,或者圖標和文字都有,相信用過Windows我的電腦工具欄自定義的都知道,標簽可選為「顯示文本標簽」(就是顯示在圖標下面)或「選擇性地文本置於右側」這就是第1點為什麼只能選2個值的原因了。
至於怎麼用圖標,再拖一個ImageList控制項進窗體,設計時插入所有要用到的圖標,記住每個圖標的索引編號,在Toolbar控制項中設置按鈕圖像為索引編號,0為沒有圖標。
編程時實現採用
Toolbar1.Buttons(1).Image = 索引
③ android v7包里的toolbar,怎麼定製圖標,字體居中的效果
Toolbar自己的文字是不支持居中效果的,只有在Toolbar裡面寫一個TextView,讓其居中可以達到居中的效果,把Toolbar的文字不寫
④ android v7包里的Toolbar,怎麼定製圖標,字體居中的效果
首先使用 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);
⑤ android toolbar 為什麼在導航欄上面
這是由於MaterialDesign設計中存在Z軸概念。按層級關系toolbar位於Activity的上方,需要將toolbar降層級,使其與activity同一層級。可以在程序裡面寫這樣的代碼,就會把toolbar當做actionbar,就不會遮擋了
⑥ Android ToolBar上的menu圖標怎麼在點擊之後更換
對於點擊就能改變狀態的 一般都是在drawable中自定義一個xml文件使用
<selector>
<item android:state_pressed="false">
//...
</item>
<item android:state_pressed="true>
//...
</item>
</selector>
⑦ android 怎樣獲取toolbar上的菜單控制項
toolbar一般是不可能遮住其它控制項的,toolbar是工具欄。通常在操作系統,Office 2010或其它軟體的界面中都有一個工具欄。 在PS中,界面左側有鋼筆工具,索引工具,圖章工具等等的一個框也是工具欄,也叫工具箱。 在計算機顯示器的圖形用戶界面上,工具欄放置了界面按鈕、圖標、菜單或其它輸入/輸出元素。 工具欄是顯示點陣圖式按鈕行的控制條,點陣圖式按鈕用來執行命令。按工具欄按鈕相當於選擇菜單項;如果某個菜單項具有和工具欄按鈕相同的ID,那麼使用工具欄按鈕將會調用映射到該菜單項的同一個處理程序。可以配置按鈕,使其在外觀和行為上表現為普通按鈕、單選按鈕或復選框。工具欄通常與框架窗口的頂部對齊,但 MFC工具欄可「停靠」在其父窗口的任何一邊或在它自己的袖珍框架窗口中浮動。工具欄也可「浮動」,用戶可更改其大小並用滑鼠拖動它。當用戶將滑鼠移動到工具欄按鈕上時,工具欄還可顯示工具提示。工具提示是個彈出的小窗口,簡要描述按鈕的作用。 有些應用程序,如圖形編輯軟體,允許工具欄分離並在窗口或其它工具欄之間移動。工具欄在辦公軟體套裝上很常見,如OpenOffice.org、圖形編輯軟體以及網頁瀏覽器如Inkscape和Mozilla Firefox。
⑧ android v7包里的Toolbar,怎麼定製圖標,字體居中的效果
首先使用 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);