❶ 如何實現android透明導航欄
1、androidkitkat 有一個新的特性可以設置手機狀態欄的背景,讓手機整個界面的風格保持一致,看起來非常清爽。
2、android4.4提供了一套能透明的系統ui樣式給狀態欄和導航欄,這樣的話就不用向以前那樣每天面對著黑乎乎的上下兩條黑欄了,還可以調成跟activity 一樣的樣式,形成一個完整的主題。
3、首先要打開activity的透明主題功能,可以把activity的主題設置繼承*.TranslucentDecor 主題,然後設置android:windowTranslucentNavigation或者android:windowTranslucentStatus的主題屬性為true,又或者在activity的代碼裡面開啟FLAG_TRANSLUCENT_NAVIGATION或是FLAG_TRANSLUCENT_STATUS的window窗口標識。由於透明主題不能在4.4以前的版本裡面使用,所以系統樣式跟以前沒有區別,也就是看不到任何變化,這是一個兼容模式,這個模式可以兼容到api 10。
❷ 如何實現Android透明導航欄
1.步驟:
1) 創建一個工程,主布局就先做一個ImageView,自己找個好看的圖片做src。
2) 在Activity重寫的onCreate方法中獲得窗口視圖對象(DecorView)
3) 設置DecorView的SystemUiVisibility
4) 設置導航條、狀態欄的顏色–>透明
5) 獲取當前Activity的ActionBar並隱藏
2.具體代碼和注釋:
獲取DecorView對象
java">@Override
protectedvoidonCreate(BundlesavedInstanceState){
...
ViewdecorView=getWindow().getDecorView();
...
}
設置SystemUiVisibility
intoption=View.SYSTEM_UI_FLAG_FULLSCREEN//全屏標記
|View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN//布局全屏標記,避免退出全屏模式時內容被覆蓋
|View.SYSTEM_UI_FLAG_HIDE_NAVIGATION//隱藏導航欄標記
|View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION//布局隱藏導航欄標記,同理
|View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY//粘性沉浸體驗
|View.SYSTEM_UI_FLAG_LAYOUT_STABLE;//確保上述標記穩定//此方法用來設置系統UI的可見性,系統UI包括狀態欄、ActionBar、導航欄devorView.setSystemUiVisibility(option);
設置狀態欄、導航欄的顏色:
getWindow().setStatusBarColor(Color.TRANSPARENT);//Color.TRANSPARENT=0表示#00000000即透明顏色
getWindow().setNavigationBarColor(Color.TRANSPARENT);
獲取本頁面的ActionBar並隱藏起來
ActionBaractionBar=getSupportActionBar();//注意:此處用的Activity繼承的是
AppCompatActivity(它繼承的是FragmentActivity)
//所以調用的是getSupport...方法,如果繼承Activity則直接調用get...方法
assertactionBar!=null;//這一句可以不理會,反正我是Ctrl+F1提示出來的,意思其實是判斷如果actionBar不為空則向下執行。
actionBar.hide();
注意:最後一點注意事項是:只支持Android API 21以上的手機
❸ android標題欄透明度漸變
<alpha>標簽為alpha透明度節點
android:fromAlpha="1.0" 設置動畫起始透明度為1.0 表示完全不透明
android:toAlpha="0.0"設置動畫結束透明度為0.0 表示完全透明
也就是說alpha的取值范圍為0.0 - 1.0 之間
這個動畫布局設置動畫從完全不透明漸變到完全透明。
view plain
<?xml
version="1.0"
encoding="utf-8"?>
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:repeatCount="infinite"
android:ration="2000">
</alpha>
代碼實現
view plain
import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
public
class AlphaActivity extends Activity {
/**顯示動畫的ImageView**/
ImageView mImageView = null;
/**透明動畫**/
Animation mAnimation = null;
@Override
public
void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.translate);
/**拿到ImageView對象**/
mImageView = (ImageView)findViewById(R.id.imageView);
/**載入透明動畫**/
mAnimation = AnimationUtils.loadAnimation(this, R.anim.alpha);
/**播放透明動畫**/
mImageView.startAnimation(mAnimation);
}
}
❹ Android 狀態欄透明
前言:最近項目大量用到狀態欄透明,網上也出現很多庫可以直接拿來用,個人認為沒有必要那麼重引用到一個庫(有木有同學和我有一樣的想法),所以研究了一番,在此做個記錄加強記憶也便後期查閱,如果無意中有幸能幫助到你那就再好不過了。
Android 從 4.4 (SDK 19) 開始支持 系統欄(狀態欄+導航欄)半透明 效果:
翻譯一下就是:
TranslucentDecor 主題設置了兩個屬性 windowTranslucentStatus 和 windowTranslucentNavigation 都為 true,前者指定狀態欄半透明、後者指定導航欄半透明。
本文只探討「狀態欄」 。
默認樣式是這樣:
可見 Toolbar 和系統狀態欄之間有明顯的分界,我們要實現的效果是 Toolbar 和狀態欄背景統一,看起來像是一個整體(自行腦補圖片)。
按照官方文檔,我們自定義主題:
對應的 Activity 引用該主題:
我看來看看效果:
雖然實現了半透明,但是布局被狀態欄覆蓋,接下來在布局文件中設置 fitSystemWindows (注意加到根節點 ConstraintLayout 上):
來看看效果:
雖然布局沒有被狀態欄覆蓋,但是狀態欄背景顯然這不是我們想要的效果😭
為什麼狀態欄會這么奇怪?
文章開頭的定義中我們說了,布局文件會延伸到狀態欄所佔區域下, fitsSystemWindows 的作用是給對應的 View 增加 padding(這里以 ConstraintLayout 為例),目的是為了讓其內容不被狀態欄遮擋。
在我們的布局文件中 ConstraintLayout 沒有設置背景(默認白色),所以狀態欄默認的半透明背景色和 ConstraintLayout 的白色背景疊加,就變成了上圖中的效果。
【總結】兩個基本概念:
1、 windowTranslucentStatus 設置為true之後,狀態欄默認是 半透明 的(4.4 是黑色到透明色漸變,5.0+ 是純黑色半透明),和我們要求的 透明 相去甚遠。更重要的是,布局會延伸到狀態欄底下。
2、 android:fitsSystemWindows 簡單理解 就是 View 為了適配系統狀態欄和導航欄(不被遮擋)自動 增加 padding ,當然真正的實現原理比這復雜很多而且不同的 View 可以自定義實現方式。
所以,為了實現文章開頭提出來的「狀態欄透明」效果,我們需要處理:
設置 windowTranslucentStatus 為 true,讓狀態欄半透明。
在根節點設置 android:fitsSystemWindows 使其不被狀態欄遮擋。
Android 4.4 暫時沒有辦法去掉狀態欄的漸變。
Android 5.0+ 開始支持修改狀態欄顏色,設置透明色即可把半透明去掉。
看看效果:
我們看到即使狀態欄透明了,但是其底色是一片白,因為跟節點 ConstraintLayout 沒有設置背景,大多情況下我們不會給整個跟節點設置顏色,可以考慮把 android:fitsSystemWindows 設置到子 View 上,本例中是 AppBarLayout (5.0+ 無效,只能顯式給 AppBarLayout 加 padding,可以利用其背景色),實際項目中可靈活調整。
最終效果:
至此,完成狀態欄透明效果,網上有很多庫,實際上都是基於此原理,在此基礎上再自定義 View 做為狀態欄背景。
https://developer.android.com/about/versions/android-4.4.html
❺ android標題欄icon怎樣漸變
在layout.xml文件中配置相關屬性。
[html] view plain
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<com.david.gradientuilibrary.GradientIconView
android:id="@+id/apple_icon"
app:bottom_icon="@mipmap/apple_1998"
app:top_icon="@mipmap/apple_2007"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.david.gradientuilibrary.GradientTextView
android:id="@+id/apple_label"
app:bottom_text_color="@color/apple_black"
app:text="@string/apple_logo"
app:text_size="32sp"
app:top_text_color="@color/apple_gray"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<SeekBar
android:id="@+id/gradientui_seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"/>
</LinearLayout>
代碼中實現
[java] view plain
package com.david.gradientuisample;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.SeekBar;
import com.david.gradientuilibrary.GradientIconView;
import com.david.gradientuilibrary.GradientTextView;
public class MainActivity extends AppCompatActivity {
private GradientIconView mAppleLogo;
private GradientTextView mAppleLabel;
private SeekBar mSeekbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView() {
mAppleLogo = (GradientIconView) findViewById(R.id.apple_icon);
mAppleLabel = (GradientTextView) findViewById(R.id.apple_label);
mSeekbar = (SeekBar) findViewById(R.id.gradientui_seekbar);
mSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
mAppleLogo.setIconAlpha((progress * 1.0f) / 100);
mAppleLabel.setTextViewAlpha((progress * 1.0f) / 100);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
}
❻ 如何實現Android透明導航欄
你可以重寫onTouchEvent()方法,判斷手指按下和抬起來的y位置變化,當滿足上移的條件時,改變導航欄的透明度即可
❼ 超簡單,幾行代碼搞定Android底部導航欄
咳咳,答應過年增加新功能的,沒想到拖到現在,延遲了一個來月,尷尬,尷尬
那個,我們先忽略這尷尬的事情吧,進入正題才是最重要滴
老規矩,先上效果圖:
跟原來的圖有個很明顯的區別,你們也一定都發現了,對不對。那麼顯眼的小紅點,一定都看到了吧。
當然除了這個,還增加了一項功能,雖然不是很明顯,但相信也有小夥伴發現了吧,截圖的這倆手機屏幕明顯大小不同,但是底部導航欄的大小還是相差不大滴。
是的,你們沒有看多,這次不僅增加了小紅點功能,還增加了底部導航欄的適配,你沒有聽錯,以後底部導航欄也不用那些dp、sp了,都按照UI妹子們標注的px來就可以了,再也不用為了底部導航欄去跟UI妹子解釋啥叫dp了。
好了,效果圖展示完了,現在該進入枯燥的使用介紹了。
由於這次改動有點大,所以,先介紹下上個穩定版本的用法,到底是用最新的,還是用原來的,就看各位小夥伴的意願了
上個穩定版本是1.1.3的,引用方式如下
compile 'com.hjm:BottomTabBar:1.1.3'
具體用法如下(備注都加好了,我也就不多廢話了):
最新版本是1.2.2的,引用方式如下
compile 'com.hjm:BottomTabBar:1.2.2'
其實1.2.0與1.1.3區別並不大,只有4點改動:
現在默認的,分割線高度都是設置的1個像素。這里以後也固定都用這個默認的高度了,不再對外提供修改的方法。
這就是新增加的適配了,多的也不說了,你們都懂的
標准尺寸,就是UI妹子給你提供的效果圖的屏幕尺寸,只要在init()方法里添加上標准尺寸,你就可以放肆的使用px了
這個方法就是控制小紅點顯示的方法了,index就是需要顯示或者隱藏小紅點的TabItem,isShow是一個boolean類型的參數,他是控制小紅點是否顯示的,如果為true,就會顯示小紅點;如果為false,就會隱藏小紅點
1.2.2版本新增了兩個方法
介紹到這里,超簡單的底部導航欄,第二階段就可以告一段落了。以後還會持續優化,完善的。
第三階段我打算封裝一下有中間凸起的底部導航欄,這個功能我本地已經做了,但是封裝進去的時候,封裝的不理想,這次就沒有上線,留作下次了。
最後,再上個 GitHub 地址
❽ Android View — Gradient 漸變
Android 支持三種顏色漸變, LinearGradient(線性漸變) RadialGradient (徑向漸變) SweepGradient(掃描漸變)。這三種漸變繼承自android.graphics.Shader, Paint 類通過setShader支持漸變。
線性漸變就是在線性方向的的漸變。有兩個構造函數,
第二種 構造函數是第一種的簡化版,只支持兩種顏色。
RadialGradient 是圓環一樣的的漸變,RadialGradient 同樣是兩個構造函數,
1.float centerX, float centerY 漸變的中心點 圓心
2.float radius 漸變的半徑
3.int[] colors 漸變顏色數組
4.float[] stops 和顏色數組對應, 每種顏色在漸變方向上所佔的百分比取值[0, 1]
5.Shader.TileMode tileMode 表示繪制完成,還有剩餘空間的話的繪制模式。
1.float centerX, float centerY 漸變的中心點 圓心
2.float radius 漸變的半徑
3.int centerColor, int edgeColor 中心點顏色和邊緣顏色
4.Shader.TileMode tileMode 表示繪制完成,還有剩餘空間的話的繪制模式
SweepGradient 是和角度有關的漸變。以某一點為圓心,隨著角度的大小發生漸變。
1.float cx, float cy 中心點坐標
2.int[] colors 顏色數組
3.float[] positions 數組顏色在漸變方向上所佔的百分比
1.float cx, float cy 中心點坐標
2.int color0, int color1 開始顏色 結束顏色
在LinearGradient RadialGradient 漸變中,構造函數的最後一個參數為 Shader.TileMode 類型,決定了如果View還有剩餘空間,如何繪制。
從上到下依次為:CLAMP REPEAT MIRROR
從上到下依次為:CLAMP REPEAT MIRROR
一些背景的漸變通過定義 Shape Drawable 來實現。Shape Drawable 有gradient 屬性。
❾ 怎麼在android上面做出根據形狀來漸變的效果
<shape> Android:shape=["rectangle" | "oval" | "line" | "ring"] 其中rectagle矩形,oval橢圓,line水平直線,ring環形
<shape>中子節點的常用屬性:
<gradient> 漸變
Android:startColor 起始顏色
Android:endColor 結束顏色
Android:angle 漸變角度,0從左到右,90表示從下到上,數值為45的整數倍,默認為0;
Android:type 漸變的樣式 liner線性漸變 radial環形漸變 sweep <solid > 填充
Android:color 填充的顏色
<stroke >描邊
Android:width 描邊的寬度
Android:color 描邊的顏色
Android:dashWidth 表示'-'橫線的寬度
Android:dashGap 表示'-'橫線之間的距離
<corners >圓角
Android:radius 圓角的半徑 值越大角越圓
Android:topRightRadius 右上圓角半徑
Android:bottomLeftRadius 右下圓角角半徑
Android:topLeftRadius 左上圓角半徑
Android:bottomRightRadius 左下圓角半徑
<padding >填充
android:bottom="1.0dip" 底部填充
android:left="1.0dip" 左邊填充
android:right="1.0dip" 右邊填充
android:top="0.0dip" 上面填充
Selector
根據不同的選定狀態來定義不同的現實效果 分為四大屬性:
android:state_selected 是選中
android:state_focused 是獲得焦點
android:state_pressed 是點擊
android:state_enabled 是設置是否響應事件,指所有事件
android:state_window_focused 默認時的背景圖片 引用位置:res/drawable/文件的名稱.xml
使用的方法:
Java代碼中:R.drawable.文件的名稱 XML中:Android:background="@drawable/文件的名稱"
示例:
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:Android="http://schemas.android.com/apk/res/android">
<!-- 默認時的背景圖片-->
<item Android:drawable="@drawable/pic1" />
<!-- 沒有焦點時的背景圖片 -->
<item
Android:state_window_focused="false"
android:drawable="@drawable/pic_blue"
/>
<!-- 非觸摸模式下獲得焦點並單擊時的背景圖片 -->
<item
Android:state_focused="true"
android:state_pressed="true"
android:drawable= "@drawable/pic_red"
/>
<!-- 觸摸模式下單擊時的背景圖片-->
<item
Android:state_focused="false"
Android:state_pressed="true"
Android:drawable="@drawable/pic_pink"
/>
<!--選中時的圖片背景-->
<item
Android:state_selected="true"
android:drawable="@drawable/pic_orange"
/>
<!--獲得焦點時的圖片背景-->
<item
Android:state_focused="true"
Android:drawable="@drawable/pic_green"
/>
</selector>
layer-list(多個shape)
將多個圖片或上面兩種效果按照順序層疊起來
示例:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap android:src="@drawable/android_red"
android:gravity="center" />
</item>
<item android:top="10dp" android:left="10dp">
<bitmap android:src="@drawable/android_green"
android:gravity="center" />
</item>
<item android:top="20dp" android:left="20dp">
<bitmap android:src="@drawable/android_blue"
android:gravity="center" />
</item>
</layer-list>
感覺很像多個drawable
三者可以結合使用
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<layer-list>
<item android:bottom="8.0dip">
<shape>
<solid android:color="#ffaaaaaa" />
</shape>
</item>
<item>
<shape>
<corners android:bottomLeftRadius="4.0dip" android:bottomRightRadius="4.0dip" android:topLeftRadius="1.0dip" android:topRightRadius="1.0dip" />
<solid android:color="#ffaaaaaa" />
<padding android:bottom="1.0dip" android:left="1.0dip" android:right="1.0dip" android:top="0.0dip" />
</shape>
</item>
<item>
<shape>
<corners android:bottomLeftRadius="3.0dip" android:bottomRightRadius="3.0dip" android:topLeftRadius="1.0dip" android:topRightRadius="1.0dip" />
<solid android:color="@color/setting_item_bgcolor_press" />
</shape>
</item>
</layer-list>
</item>
<item>
<layer-list>
<item android:bottom="8.0dip">
<shape>
<solid android:color="#ffaaaaaa" />
</shape>
</item>
<item>
<shape>
<corners android:bottomLeftRadius="4.0dip" android:bottomRightRadius="4.0dip" android:topLeftRadius="1.0dip" android:topRightRadius="1.0dip" />
<solid android:color="#ffaaaaaa" />
<padding android:bottom="1.0dip" android:left="1.0dip" android:right="1.0dip" android:top="0.0dip" />
</shape>
</item>
<item>
<shape>
<corners android:bottomLeftRadius="3.0dip" android:bottomRightRadius="3.0dip" android:topLeftRadius="1.0dip" android:topRightRadius="1.0dip" />
<solid android:color="@color/setting_item_bgcolor" />
</shape>
</item>
</layer-list>
</item>
</selector>
❿ android顏色漸變如何實現從四周往中心漸變 或者從中心往四周漸變 都行,不是 從左往右
android 顏色漸變是指通知xml或者java代碼,設置相關參數,是界面的某個指定的視圖顯示成從開始位置的顏色,逐漸過度到結尾位置的顏色的技術。
android顏色漸變的分類有:
LinearGradient線性漸變
RadialGradient鏡像漸變
SweepGradient角度漸變
一、LinearGradient線性漸變
顧名思義,是只顏色在一個直線方向上逐漸改變。
文件代碼:
<?xmlversion="1.0"encoding="utf-8"?>
<shapexmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<gradient
android:endColor="#0000FF"
android:startColor="#FF0000"
android:type="linear"/>
</shape>
效果: