❶ 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上面做出根據形狀來漸變的效果
您好,希望以下回答能幫助您
這個是輸出一層顏色漸變的效果,而你的是多層的,做法一樣,弄幾個小的的三角形同樣的畫法畫到上面。而顏色的值是不可能是線性的值,你只能自己定義每層三角形的顏色,這個是你要做的。
這個我直接用NDK自帶的HELLO-GL2給你弄的,就設置下三角形頂點和改了shader部分的代碼而已。
原理很簡單,設置5個頂點,第一個頂點為三角形中心頂點坐標,其他四的坐標為,三角形三個頂點坐標,其中第2和第5個頂點一樣。繪制三角形的時候使用扇形繪制。
中間頂點一個顏色,其他4個頂點為另一個顏色。
多層漸變就加幾個小點的三角形然後將顏色設置好覆蓋上去。
如您還有疑問可繼續追問。
❸ Android如何設置頂部狀態欄顏色(主題)
在Android中我們經常需要設置屏幕頂部狀態欄的主題和應用頁面保持同一風格,本文介紹幾種常用的設置方案:
首先給出一張圖:
2 2通過上圖,我們可以通過設置不同的屬性來達到控制不同位置顏色的目的,下面給出使用示例,修改res/values-19裡面的內容:
主要是設置 colorPrimary,colorPrimaryDark這兩個屬性的值來設置狀態欄的顏色,需要注意的是:
1:AndroidManifest.xml文件中的targetSdkVersion必須設置在 21 以上。
2.parent主題必須是 Theme.AppCompat 開頭,兼容包下的主題,所以必須一用 v7 包。
在頂部標題欄設置屬性值達到風格一致的目的
首先修改res/values-v19文件夾下的styles.xml文件內容如下(如果沒有可以新建一個):
然後設置頂部標題控制項的兩個屬性:
這時狀態欄會保持與設置fitsSystemWindow屬性的控制項的背景顏色一致。
❹ 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 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怎麼設置字體漸變色 不是背景漸變
●使用XML的方式為背景添加漸變效果
1、在res/drawable文件夾里添加一個jbshape.xml文件,然後寫入如下代碼:
<?xml version="1.0" encoding="utf-8"?>
<gradient
android:angle="270"
android:centerColor="#00FFFF"
android:centerX="0.5"
android:centerY="0.5"
android:endColor="#666666"
android:startColor="#0099FF" />
<padding
android:bottom="7dp"
android:left="7dp"
android:right="7dp"
android:top="7dp" />
<corners android:radius="4dp" />
</shape>
說明:
(1)shape節點配置的是圖形的形式,主要包括方形、圓形等,上邊代碼為方形。
(2)gradient節點主要配置起點顏色、終點顏色及中間點的顏色、坐標、漸變效果(0,90,180從左到右漸變,270從上到下漸變)默認從左到右。
(3)corners節點配置四周圓角的半徑。
❼ 怎麼在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 應用開發怎麼修改標題欄顏色
代碼如下:
View bv = this.findViewById(android.R.id.title );
((TextView) bv).setTextColor(Color.WHITE);
((View) bv.getParent()).setBackgroundColor(Color.RED);
這樣,即可設置標題欄背景為紅色,字體為白色
❾ 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>
效果:
❿ 怎麼在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/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/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="schemas/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>