导航:首页 > 操作系统 > 安卓怎么写样式

安卓怎么写样式

发布时间:2022-07-11 13:44:07

① 安卓开发中怎么在布局中添加显得样式

使用TableLayout表格布局

表格布局模型以行列的形式管理子控件,每一行为一个TableRow的对象,当然也可以是一个View的对象。TableRow可以添加子控件,每添加一个为一列。
TableLayout属性:
android:collapseColumns:将TableLayout里面指定的列隐藏,若有多列需要隐藏,请用逗号将需要隐藏的列序号隔开。
android:stretchColumns:设置指定的列为可伸展的列,以填满剩下的多余空白空间,若有多列需要设置为可伸展,请用逗号将需要伸展的列序号隔开。
android:shrinkColumns:设置指定的列为可收缩的列。当可收缩的列太宽(内容过多)不会被挤出屏幕。当需要设置多列为可收缩时,将列序号用逗号隔开。
列元素(Button)属性:(奇怪的是button 里面没有android:layout_column 和android:layout_span两个属性,写进去无反应,还不知道为什么)
android:layout_colum:设置该控件在TableRow中指定的列。
android:layout_span:设置该控件所跨越的列数。

② 安卓手机上怎么打出好看的字体

1、点击手机设置


(2)安卓怎么写样式扩展阅读:

花样字体设置之后,还可以通过设置字体的大小来设置自己最喜欢的状态:

不同的字体选择好以后,也能在系统中设置字体大小,就可以对手机的字体进行调整了,手机提供的调整方式有4种,分别是“小号~默认~中号~大号~超大”,只需根据需要选择就好了。

这样就会手机使用起来有不同的感觉,也能更好的匹配不同的人群, 相信这样使用会更喜欢的。

另外,有一点要注意的是:这里调整的字体大小只适用于系统本身(设置、桌面字体)的字体大小,不能改变第三方APP内字体的大小,第三方APP的字体大小需要第三方软件提供调整入口才行。不同手机的调整方法不太一样但是基本都是一样的。

③ Android开发之:如何使用样式和主题

�尘把丈�仁粜浴Q�绞谴硬季治募�蟹掷氤隼吹囊桓鲺ML资源文件。Android中的样式就像Web开发中的css样式表,它使用我们的样式独立于内容进行设计开发。 例如,通过使用一个样式可以让如下的布局文件简化为:所有和样式有关的属性都被从布局XML文件中移动到一个叫“CodeFont”的样式定义中,然后使用一个style属性指定样式名称。你将会在以下的内容中看到如何定义一个样式。应用于一个Activity或应用程序的样式称为主题(theme),而不是刚才说的一个View。所有在当前Activity或应用下的视图(VIEW)都会应用相同的主题样式。例如,您可以让一个Activity使用”CodeFont”主题,那么这个Activity下的所有视图的的文本都将是绿色等宽字体。定义样式定义样式我们需要在 res/values/目录下新建一个XML文件,文件名自已随便命名,但必须以.xml为文件后缀。Xml的根节点必须为。 我们用style标签来定义一个样式,用标签来定义样式属性。如下所示:fill_parentwrap_content#00FF00monospaceStyle标签的name属性是必须有的,节点可以定义颜色、高度或者是另一个资源的引用。所有节点的子节点在编译时都会做为应用程序的一个资源。所以我们可以通过style节点的name属性值来引用这个资源。比如在布局文件中使用@style/CodeFont来引用这个样式。parent 属性是可选的,用它来标识本样式是继承哪个样式,在父样式中的所有属性都将被应用于本样式中,同时可以覆盖父样式中的样式(和java的继承相似)。样式的继承这里有两种方式可以实现样式继承,如上例中所示的,我们可以在定义样式时使用parent属性来继承样式,使用这种方式,我们可以继承一个我们自己定义好的样式,也可以继承一个android平台自带的样式(后文中会介绍android平台自带的所有样式)。如下所示,我们继承一个android平台默认的文本样式,并把它的字体颜色改为我们需要的颜色。#00FF00另一种继承的方式是使用用户自定义的样式作为前缀即可。这种方式只适用于继承用户自定义样式。如下所示:#FF0000这样,新定义的样式就会继承CodeFont样式的所有属性,然后把字体颜色变为#FF0000。我们可以这样引用新的样式: @style/CodeFont.Red 相同的方法,我们可以再继承下去,如下所示:30sp这样新的样式文子的大小就和CodeFont.Red样式不同了。样式属性到这里为止,你已经知道了如何定义一个样式,你还需要知道有多少种样式属性可以通过节点来定义。你可能已经对其中的一些比较熟悉了,如layout_width 、textColor等。当然,还有很多的样式属性是你可以使用的。

④ Android 中怎么设置全局自定义字体样式

  1. 首先下载自定义字体,拷贝到工程中的assets文件夹下,建个新文件夹也可以。

  2. 创建一个继承自Application的类,放上TypeFace的变量。

  3. 将系统的serif的字体替换成微软雅黑。

  4. 最后自定义的主题。

⑤ Android 怎样在styles.xml中定义自己的样式并引用样式

下面是styles.xml文件中相关的部分:

[html] view plain print?

<stylename="text_font">

<itemname="android:textColor">#05b</item>

<itemname="android:textSize">18sp</item>

<itemname="android:textStyle">bold</item>

</style>

<stylename="content_font">

<itemname="android:textColor">#0f5</item>

<itemname="android:textSize">18sp</item>

<itemname="android:textStyle">normal</item>

</style>

<stylename="hint_text_font"parent="text_font">

<itemname="android:textColor">#f00</item>

</style>

<style name="text_font">
<item name="android:textColor">#05b</item>
<item name="android:textSize">18sp</item>
<item name="android:textStyle">bold</item>
</style>

<style name="content_font">
<item name="android:textColor">#0f5</item>
<item name="android:textSize">18sp</item>
<item name="android:textStyle">normal</item>
</style>

<style name="hint_text_font" parent="text_font">
<item name="android:textColor">#f00</item>
</style>


我们在界面元素中这样引用:

[html] view plain print?

<TextViewstyle="@style/content_font"

android:id="@+id/textView1"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/hello_world"/>

<Buttonstyle="@style/text_font"

android:id="@+id/button1"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/test_IntentService"/>

<TextViewstyle="@style/hint_text_font"

android:id="@+id/hint"

android:text="@string/hint_text"

android:layout_height="wrap_content"

android:layout_width="fill_parent"/>

上面截图就是通过自定义样式实现的,例子来自android学习手册,里面有源码。android学习手册包含9个章节,108个例子,源码文档随便看,例子都是可交互,可运行,源码采用android studio目录结构,高亮显示代码,文档都采用文档结构图显示,可以快速定位。360手机助手中下载,图标上有贝壳:

⑥ 如何自定义android Button样式

亲,可以用到Drawable中的shape哦,给你一个demo

<?xmlversion="1.0"encoding="utf-8"?>
<selectorxmlns:android="

<itemandroid:state_focused="false">
<shape>
<solidandroid:color="@color/find_passwordbar_bg"/>
<strokeandroid:width="0.5dp"android:color="#C8C8C8"/>
</shape>
</item>

<itemandroid:state_focused="true">
<shape>
<solidandroid:color="@color/find_passwordbar_bg"/>
<strokeandroid:width="0.5dp"android:color="@color/main_color"/>
</shape>
</item>

</selector>

各个属性的介绍

solid:实心,就是填充的意思
android:color指定填充的颜色

gradient:渐变
android:startColor和android:endColor分别为起始和结束颜色,ndroid:angle是渐变角度,必须为45的整数倍。
另外渐变默认的模式为android:type="linear",即线性渐变,可以指定渐变为径向渐变,android:type="radial",径向渐变需要指定半径android:gradientRadius="50"。

stroke:描边
android:width="2dp"描边的宽度,android:color描边的颜色。
我们还可以把描边弄成虚线的形式,设置方式为:
android:dashWidth="5dp"
android:dashGap="3dp"
其中android:dashWidth表示'-'这样一个横线的宽度,android:dashGap表示之间隔开的距离。

corners:圆角
android:radius为角的弧度,值越大角越圆。
我们还可以把四个角设定成不同的角度,方法为:
<corners
android:topRightRadius="20dp"右上角
android:bottomLeftRadius="20dp"右下角
android:topLeftRadius="1dp"左上角
android:bottomRightRadius="0dp"左下角
/>

我自己写的一个按钮,效果就像图中所示,用的Shape



新建后存放位置在res/drawable下


希望能帮到你,还望采纳

⑦ 简述Android 中样式文件使用步骤

在Eclipse中android程序项目目录结构下的res文件夹新建drawable文件夹,并在drawable文件夹下新建各类的xml样式文件,供layout文件夹下的xml布局文件引用,以满足对程序界面的需求开发。如图1和图2是drawable下xml样式文件的样式类型。

图3、iv1到iv4
其次是信号增强即图片顺序播放的效果,在drawable下新建animation_list_sequence.xml样式文件。

<?xml version="1.0" encoding="utf-8"?><!--
根标签为animation-list;
其中oneshot代表着是否只展示一遍,设置为false会不停的循环播放动画;
其中visible规定drawable的初始可见性,默认为flase;
其中variablePadding若为true则允许drawable的距离在当前选择状态下有所改变(If true, allows the drawable’s padding to change based on the current state that is selected.),默认为false;
根标签下,通过item标签对动画中的每一个图片进行声明;
android:ration 表示展示所用的该图片的时间长度,单位为毫秒;
--><animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true"
android:visible="false"
android:variablePadding="false"
>
<item android:drawable="@drawable/iv1" android:ration="200"></item>
<item android:drawable="@drawable/iv2" android:ration="200"></item>
<item android:drawable="@drawable/iv3" android:ration="200"></item>
<item android:drawable="@drawable/iv4" android:ration="200"></item></animation-list>

再者是信号增强即图片顺序播放的效果,在drawable下新建animation_list_reverse.xml样式文件。

<?xml version="1.0" encoding="utf-8"?><!--
根标签为animation-list;
其中oneshot代表着是否只展示一遍,设置为false会不停的循环播放动画;
其中visible规定drawable的初始可见性,默认为flase;
其中variablePadding若为true则允许drawable的距离在当前选择状态下有所改变(If true, allows the drawable’s padding to change based on the current state that is selected.),默认为false;
根标签下,通过item标签对动画中的每一个图片进行声明;
android:ration 表示展示所用的该图片的时间长度,单位为毫秒;
--><animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true"
android:visible="false"
android:variablePadding="false"
>
<item android:drawable="@drawable/iv4" android:ration="200"></item>
<item android:drawable="@drawable/iv3" android:ration="200"></item>
<item android:drawable="@drawable/iv2" android:ration="200"></item>
<item android:drawable="@drawable/iv1" android:ration="200"></item></animation-list>

然后在layout文件夹下新建xml布局文件activity_animation_list.xml,引用上面写好的drawable文件夹下的xml样式文件。

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ImageView android:id="@+id/iv_animation_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/animation_list_sequence" />

<Button android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="sequence"
android:text="顺序显示" />

<Button android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="stop"
android:text="停止动画" />

<Button android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="reverse"
android:text="倒序显示" /></LinearLayout>2122232425262728293031

然后在src包下新建Activity的Java文件AnimationListActivity.java,用于演示操作。

package com.zcz.drawablexmltest;import android.app.Activity;import android.graphics.drawable.AnimationDrawable;import android.os.Bundle;import android.view.View;import android.view.Window;import android.widget.ImageView;public class AnimationListActivity extends Activity{
private ImageView mIv;
private AnimationDrawable mAd;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_animation_list);
mIv = (ImageView) findViewById(R.id.iv_animation_list);
}

public void sequence(View view){
mIv.setImageResource(R.drawable.animation_list_sequence);
mAd = (AnimationDrawable) mIv.getDrawable();
mAd.start();
} public void stop(View view){
mAd = (AnimationDrawable) mIv.getDrawable();
mAd.stop();
} public void reverse(View view){
mIv.setImageResource(R.drawable.animation_list_reverse);
mAd = (AnimationDrawable) mIv.getDrawable();
mAd.start();
}
}

⑧ 如何修改Android App的样式风格

android中可以自定义主题和风格。风格,也就是style,我们可以将一些统一的属性拿出来,比方说,长,宽,字体大小,字体颜色等等。可以在res/values目录下新建一个styles.xml的文件,在这个文件里面有resource根节点,在根节点里面添加item项,item项的名字就是属性的名字,item项的值就是属性的值,如下所示:
复制代码 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyText" parent="@android:style/TextAppearance">
<item name="android:textColor">#987456</item>
<item name="android:textSize">24sp</item>
</style>
</resources>

style中有一个父类属性parent, 这个属性是说明当前的这个style是继承自那个style的,当然这个style的属性值中都包含那个属性中的,你也可以修改继承到的属性的值,好了,style完成了,我们可以测试一下效果了,先写一个布局文件,比如说一个TextView什么的,可以用到这个style的。这里我就写一个EditText吧。下面是布局文件:
复制代码 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas。android。com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/myEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/MyText"
android:text="测试一下下"/>
</LinearLayout>

说完了style,下面就说说Theme,Theme跟style差不多,但是Theme是应用在Application或者Activity里面的,而Style是应用在某一个View里面的,还是有区别的,好了,废话不多说,还是看代码吧。下面的是style文件:
复制代码 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyText" parent="@android:style/TextAppearance">
<item name="android:textColor">#987456</item>
<item name="android:textSize">24sp</item>
</style>
<style parent="@android:style/Theme" name="CustomTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFrame">@drawable/icon</item>
<item name="android:windowBackground">?android:windowFrame</item>
</style>
</resources>

style中有一个父类属性parent, 这个属性是说明当前的这个style是继承自那个style的,当然这个style的属性值中都包含那个属性中的,你也可以修改继承到的属性的值,好了,style完成了,我们可以测试一下效果了,先写一个布局文件,比如说一个TextView什么的,可以用到这个style的。这里我就写一个EditText吧。下面是布局文件:
复制代码 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas。android。com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/myEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/MyText"
android:text="测试一下下"/>
</LinearLayout>

说完了style,下面就说说Theme,Theme跟style差不多,但是Theme是应用在Application或者Activity里面的,而Style是应用在某一个View里面的,还是有区别的,好了,废话不多说,还是看代码吧。下面的是style文件:
复制代码 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="MyText" parent="@android:style/TextAppearance">
<item name="android:textColor">#987456</item>
<item name="android:textSize">24sp</item>
</style>
<style parent="@android:style/Theme" name="CustomTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFrame">@drawable/icon</item>
<item name="android:windowBackground">?android:windowFrame</item>
</style>
</resources>

可以看到这里写了一个继承自系统默认的Theme的主题,里面有3个属性,这里强调一下第三个属性的值的问题,这里打个问号,然后加前面的一个item的名字表示引用的是那个名字的值,也就是那个名字对应的图片。
然后我们在Manifest.xml里面的Application里面加一个Theme的属性,这个属性对应的就是我们上面写的Theme。
复制代码 代码如下:

<application android:icon="@drawable/icon" android:label="@string/app_name"
android:theme="@style/CustomTheme">
<activity android:name=".TestStyle"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

上面的代码没有标题栏,背景和fram都是我们设置的图片。当然也可以在代码中设置主题:
复制代码 代码如下:

package com.test.shang;
import android.app.Activity;
import android.os.Bundle;
public class TestStyle extends Activity {
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.CustomTheme);
setContentView(R.layout.test_style);
}
}

阅读全文

与安卓怎么写样式相关的资料

热点内容
华为adb命令行刷机 浏览:963
人像摄影pdf 浏览:755
解压文件密码怎样重新设置手机 浏览:999
高考指南pdf 浏览:693
爬虫python数据存储 浏览:240
u盘怎么取消加密 浏览:429
567除以98的简便算法 浏览:340
pdf手机如何解压 浏览:15
python描述器 浏览:60
战地联盟3解压密码 浏览:805
s型命令 浏览:25
php年薪5年 浏览:71
如何上网上设个人加密账户 浏览:44
linux打开ssh服务 浏览:78
微信位置可以加密吗 浏览:470
算法蛮力法 浏览:438
随机排练命令 浏览:147
python多进程并发 浏览:41
安卓软件安装如何躲避安全检测 浏览:647
奇幻潮翡翠台源码百度云盘 浏览:187