android样式定义,安卓开发样式-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

android样式定义,安卓开发样式

Android Studio控件设置样式怎么设置

1、样式定义

创新互联主要从事网站设计、做网站、网页设计、企业做网站、公司建网站等业务。立足成都服务大箐山,十年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18982081108

android的样式定义在res/values/style.xml文件中,类似web前端中将样式定义在某个css文件中,但android的style.xml是自动加载的,不需要手动import或link。目前还不了解android是否可以或怎么定义多个style文件。

如下是一组样式的定义

[xml]

span style="background-color: rgb(255, 255, 255);" !-- 全局字体样式--

style name="DefaultFontStyle"

item name="android:textSize"18px/item

item name="android:textColor"#0000CC/item

/style

!-- 全局背景色--

style name="DefaultBgColor" parent="@style/DefaultFontStyle"

item name="android:background"#F2F2F2/item

/style

!-- 全局样式--

style name="DefaultStyle" parent="@style/DefaultBgColor"

/style/span

a. android的样式定义是通过style标签完成的,通过添加item元素设置不同的属性值

b. 样式可以通过设置parent进行继承。上面的DefaultBgColor继承自DefaultFontStyle,而DefaultStyle又继承自DefaultBgColor,这样DefaultStyle就有了字体大小颜色、背景色的属性了。

c. android的主题样式和一般样式的定义是一样的,只是引用时不同

2、单个view如何设置样式 

比如TextView,设置样式如下 

[xml]

span style="background-color: rgb(255, 255, 255);"TextView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="我在做什么:"

android:textSize="18px"

android:textColor="#0000CC"

//span

也可以引用第一部分定义的样式,如下

[xml]

span style="background-color: rgb(255, 255, 255);"TextView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="我在做什么:"

style="@style/DefaultStyle"

//span

设置view的style属性进行样式调用,推荐使用此种方式将样式和布局分离。其他view及viewGroup设置相同。

 

3、全局样式设置

在web前端编程中,可以使用 

[html]

span style="background-color: rgb(255, 255, 255);"body {

background: #cce8cf;

color: #000;

font-family: 宋体 verdana, tahoma;

font-size: 18px;

padding: 1px 2px 0 2px;

counter-reset: section;

}/span

设置全局的样式

 

[html]

span style="background-color: rgb(255, 255, 255);"div {

margin-top: 10px;

margin-bottom: 10px;

}/span

设置单个标签的样式

如何自定义android Button样式

//1.在项目的 res\values\styles.xml 里面自己写一个样式 ,parent="android:Widget.Button",name 随便,比如我的:

?xml version="1.0" encoding="utf-8"?

resources

style name="Theme.Button" parent="android:Widget.Button" 

item name="android:background"@android:color/darker_gray/item

item name="android:focusable"true/item

item name="android:clickable"true/item

item name="android:textColor"@android:color/black/item

item name="android:gravity"center_vertical|center_horizontal/item

/style

/resources

//2.在自己的布局代码中设置button 样式

Button

style="@style/Theme.Button"

android:text="Hello"

android:layout_width="500dp"

android:layout_height="50dp"/

如何自定义Android Dialog的样式?

Android 中自定义Dialog的样式,主要是通过自定义的xml,然后加载到dialog的背景中,如下步骤:

1、自定义Dialog

final Dialog dialog = new Dialog(this, R.style.Theme_dialog);

2、窗口布局

View contentView = LayoutInflater.from(this).inflate(R.layout.select_list_dialog,null);

3、把设定好的窗口布局放到dialog中

dialog.setContentView(contentView);

4、设定点击窗口空白处取消会话

dialog.setCanceledOnTouchOutside(true);

5、具体的操作

ListView msgView = (ListView)contentView.findViewById(R.id.listview_flow_list);

6、展示窗口

dialog.show();

例:

final Dialog dialog = new Dialog(this,R.style.Theme_dialog);

View contentView =LayoutInflater.from(this).inflate(R.layout.select_list_dialog, null);

dialog.setContentView(contentView);

dialog.setCanceledOnTouchOutside(true);

ListView msgView = (ListView)contentView.findViewById(R.id.listview_flow_list);

TextView titleText = (TextView)contentView.findViewById(R.id.title);

titleText.setText("请选择银行卡");

SelectBankCardDialogAdapter adapter =new SelectBankCardDialogAdapter(this, mBankcardList);

msgView.setAdapter(adapter);

msgView.setOnItemClickListener(newOnItemClickListener() {

@Override

public void onItemClick(AdapterViewparent, View view, int position, long id) {

//Toast.makeText(RechargeFlowToMobileActivity.this,

// position+"",0).show();

mSelectCard =mBankcardList.get(position);

String area = mSelectCard.getBank_card();

mCardNumberText.setText(area);

dialog.dismiss();

}

});

Button closeBtn = (Button)contentView.findViewById(R.id.close);

closeBtn.setClickable(true);

closeBtn.setOnClickListener(newView.OnClickListener() {

@Override

public void onClick(View v) {

dialog.dismiss();

}

});

dialog.show();

以上就是在Android开发自定义dialog样式的方法和步骤,android很多的控件都提供了接口或者方法进行样式的定义和修改。

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

使用stackoverflow软件进行修改。

操作

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

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

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

最后自定义的主题。


分享标题:android样式定义,安卓开发样式
标题网址:http://kswsj.cn/article/dscogjc.html

其他资讯