backgroundcolor渐变 background颜色代码
其实backgroundcolor渐变的问题并不复杂,但是又很多的朋友都不太了解background颜色代码,因此呢,今天小编就来为大家分享backgroundcolor渐变的一些知识,希望可以帮助到大家,下面我们一起来看看这个问题的分析吧!
jquery 怎样让css内容有渐变效果
动态渐变
<span style="font-size:12px;"><html>
<body>
<center>
<div id="fade" style="width:600px;height:200px;"></div>
</center>
</body>
</html></span>
为了方便查看,使用内嵌样式,还是推荐使用外链样式的使用啊,接下来进行简单编写动态实现渐变效果
<span style="font-size:12px;"><script type="text/javascript">
var node=document.getElementById("fade");
var color="#0000";
var level=1;
window.load=function fading(){
node.style.background=color.+level.toString()+level.toString();
level++;
if(level>16){
clearTimeOut(fading);
}else{
setTimeOut(fading,300);
}
}
<script></span>
静态渐变
在css样式中添加:
background:-webkit-gradient(linear, 100% 0%, 0% 0%, from(#ffffff),color-stop(0.5,#0000ff),to(#ffffff));
简单解释:
linear:这个就碰到了线性渐变和径向渐变的两个概念,无非是在一条线上进行变化的线性和像圆一样向四周扩散的径向;
后面的四个值:分别代表相应方向的px值,可以从左顺时针转的顺序记忆,但是它代表的是to,截止到的颜色
from:这就是开始的颜色了
to:和from是同时出现的,最后渐变结束的颜色
而color-stop:则是指在变化到线的哪个位置的时候会出现什么颜色,当然是从周围过渡过去的,相当于from,to过渡点,from过渡点,to。
android怎么设置状态栏和actionbar同颜色
android布局 layout relativelayout
除了沉浸模式外,Android 4.4还有新的API,能使应用内的状态栏和虚拟按钮透明。其他更多的Android 4.4 APIs可以看这里。
如果要使应用内的状态栏和虚拟按钮变成透明有两种方法。
一种是代码方式:
?1
2
3Window window= getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
另外一种是使用两个新的主题风格:
Theme.Holo.NoActionBar.TranslucentDecor和Theme.Holo.Light.NoActionBar.TranslucentDecor。
但是这种方式只支持Android4.4以上系统,所以为了保持兼容性,我们还是采用代码方式比较好。只需要先判断,如果是4.4以上系统才启用代码。
开启后上下系统栏都透明了。
但是如果应用本身是带有actionbar或者标题栏的话会就会变得比较尴尬,内容会在上面露出来。这个时候需要在布局文件里加入android:fitsSystemWindows="true"。
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#c8c8c8">
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
但是这样的话内容就不能从透明的虚拟按钮下穿过,没原来那么好看。我们可以按照以前一样把根布局设置一个高度为系统栏高度和ActionBar高度的内边距就可以。
同时关于获取ActionBar和状态栏的高度,发现用原来的方法有时候会获取的值为0。自己google找了一下,找到两个前辈提供的获取高度方法,获取ActionBar高度,获取状态栏高度。
8if(android.os.Build.VERSION.SDK_INT> 18){
Window window= getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION,
WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
//设置根布局的内边距
RelativeLayout relativeLayout=(RelativeLayout)
findViewById(R.id.layout);
relativeLayout.setPadding(0, getActionBarHeight()+getStatusBarHeight(), 0,
0);
}
27//获取手机状态栏高度
public int getStatusBarHeight(){
Class c= null;
Object obj= null;
Field field= null;
int x= 0, statusBarHeight= 0;
try{
c= Class.forName("com.android.internal.R$dimen");
obj= c.newInstance();
field= c.getField("status_bar_height");
x= Integer.parseInt(field.get(obj).toString());
statusBarHeight= getResources().getDimensionPixelSize(x);
} catch(Exception e1){
e1.printStackTrace();
}
return statusBarHeight;
}
//获取ActionBar的高度
public int getActionBarHeight(){
TypedValue tv= new TypedValue();
int actionBarHeight= 0;
if(getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))//
如果资源是存在的、有效的
{
actionBarHeight= TypedValue.complexToDimensionPixelSize(tv.data,
getResources().getDisplayMetrics());
}
return actionBarHeight;
}
接下来,因为我自己写的一些应用是暗色的主题的,会导致透明的状态栏和ActionBar颜色不太协调。看到有一些应用是把状态栏的颜色设置成和ActionBar一样,这种解决方法也不错。
具体是怎么实现的也不太清楚,我自己猜测写了一个差不多状态栏。我是直接在根视图加入一个高度为状态栏高度的TextView,背景设置为和ActionBar一样。具体代码如下:
8//创建TextView
TextView textView= new TextView(this);
LinearLayout.LayoutParams lParams= new
LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, getStatusBarHeight());
textView.setBackgroundColor(Color.parseColor("#3F9FE0"));
textView.setLayoutParams(lParams);
//获得根视图并把TextView加进去。
ViewGroup view=(ViewGroup) getWindow().getDecorView();
view.addView(textView);
在模拟器上看还行,但是在实际的手机当中总感觉ActionBar有点过大,所以我在背景色里加入了一些渐变,在实体手机中就比较好看一点,不会觉得ActionBar太宽了。
android:startColor="#c8c8c8"
android:endColor="#3F9FE0"
android:angle="270"
android:type="linear"/>
文章到此结束,如果本次分享的backgroundcolor渐变和background颜色代码的问题解决了您的问题,那么我们由衷的感到高兴!