- 浏览: 1096036 次
- 性别:
- 来自: 郑州
文章分类
最新评论
-
baiyi168:
非常有用,多谢楼主
Android中的一个TextView中的字体设置不同大小 -
qq271629261:
[img] ...
android开发工具 Eclipse+Android SDK+ADT -
txlong_onz:
haotainan 写道Activity伪造Dialog,这个 ...
Activity伪造Dialog的时候不能全屏显示 -
haotainan:
Activity伪造Dialog,这个Dialog显示的时候界 ...
Activity伪造Dialog的时候不能全屏显示 -
gangbener:
cainingyouyou 写道7楼的,tag,怎么解决的啊1 ...
android中ListView点击和里边按钮或ImageView点击不能同时生效问题解决
1.sytle:Android中的style就是用简单的配置来实现页面的外观和风格的方式。他是一个包含一个或者多个view控件属性的集合,可以当成一个整体应用到XML单个元素上。
例如我们可以在res/values/styles.xml文件,键入代码:
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="style1"> <!-- 为样式定义一个全局唯一的名字--> <item name="android:textSize">18px</item> <!-- name属性为样式要用在的View控件持有的属性 --> <item name="android:textColor">#0000CC</item> <!-- 等等…… --> <item name="android:layout_width">60dip</item> <item name="android:layout_height">50dip</item> <item name="android:layout_weight">1</item> <item name="android:divider">#FFCFCFCF</item> <item name="android:dividerHeight">0.5dip</item> <item name="android:listSelector">@drawable/list_item_bg</item> <item name="android:cacheColorHint">#00000000</item> </style> <style name="TitleStyle"> <item name="android:textSize">18sp</item> <item name="android:textColor">#ec9237</item> </style> <style name="LinkStyle"> <item name="android:textSize">18sp</item> <item name="android:textColor">#ec0032</item> <item name="android:fromAlpha">0.0</item> <item name="android:toAlpha">0.0</item> </style> <style name="SpecialText"> <item name="android:textSize">28sp</item> <item name="android:textColor">@color/darkgreen</item> <item name="android:gravity">center</item> <item name="android:textStyle">bold|italic</item> <item name="android:background">@drawable/icon</item> </style> </resources>
这其实也就是把view的属性罗列出来,用一个view关联。这样在遇到view配置相同的属性的时候就可以直接通过这个名字直接关联这样的样式设置了。其实这个还想是WEB开发中的CSS的使用。就是把view的属性单独写出,提高重用性。
在layout文件中可以像下面这样使用上面的android样式:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView style="@style/TitleStyle" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_vertical|center_horizontal" android:text="txlong_onz ai slna" /> <TextView style="@style/LinkStyle" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_vertical|center_horizontal" android:text="http://txlong-onz.iteye.com" android:autoLink="all" /> <TextView style="@style/SpecialText" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_vertical|center_horizontal" android:text="SpecialText" /> </LinearLayout>
<style>标签中有一个parent属性。这个属性可以让当前样式继承一个父样式,当前样式可以继承到父样式的值。当然,如果父样式的值不符合你的需求,你也可以对它进行修改,和CSS中的覆盖效果一样,都是以最后的为准,例子如下:
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="style1"> <item name="android:textSize">18px</item> <!-- name属性为样式要用在的View控件持有的属性 --> <item name="android:textColor">#0000CC</item> </style> <style name="subitcast" parent="@style/style1"> <item name="android:textColor">#FF0000</item> </style> </resources>
样式的继承,一种是继承平台自带的。一种是继承自定义的样式。继承平台原有的一定要parent指定。
<style name="GreenText" parent="@android:style/TextAppearance"> <item name="android:textColor">#00FF00</item> </style>
继承自定义的只需在name前加要继承的style主题就行了。<style name="GreenText.Red">
<item name="android:textColor">#FF0000</item> </style>
这种方法可以不断地继承
<style name="CodeFont.Red.Big"> <item name="android:textSize">30sp</item> </style>
2.theme:Android主题设置其实就是将主题添加到一个配置里,以方便调用,提高重用性。所以配置文件的属性也就是窗口等的主题样式。
<?xml version="1.0" encoding="utf-8"?> <resources> <style name="theme1"> <item name="android:windowNoTitle">true</item> <item name="android:windowFullscreen">?android:windowNoTitle</item> </style> </resources>
上面"?android:windowNoTitle"中的问号用于引用在当前主题中定义过的资源的值。下面代码显示在AndroidManifest.xml中如何为应用设置上面定义的主题:
<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/theme1"> <activity android:name=".MessageShowActivity" android:label="@string/app_name" android:windowSoftInputMode="adjustPan" android:screenOrientation="portrait" android:theme="@style/theme2"> </activity> </application>
除了可以在AndroidManifest.xml中设置主题,同样也可以在代码中设置主题,如下:
setTheme(R.style.theme1);
尽管在定义上,样式和主题基本相同,但是它们使用的地方不同。样式用在单独的View,如:EditText、TextView等;主题通过AndroidManifest.xml中的<application>和<activity>用在整个应用或者某个 Activity,主题对整个应用或某个Activity存在全局性影响。如果一个应用使用了主题,同时应用下的view也使用了样式,那么当主题与样式属性发生冲突时,样式的优先级高于主题。
另外android系统也定义了一些主题,例如:
<activity android:theme="@android:style/Theme.Dialog">,该主题可以让Activity看起来像一个对话框,
<activity android:theme="@android:style/Theme.Black.NoTitleBar">Variant of the light theme with no title bar,系统自带的黑色主题。如果需要查阅这些主题,可以在文档的reference-->android-->R.style 中查看。
3.AlertDialog的使用Demo:
主要的类在这里粘出来,style和theme自己下载下边的附件。
public class StyleThemeTest extends Activity { public final String TAG = "Test"; private Dialog mDialog; private Button button1; private Button button2; private Button button3; @Override public void onCreate(Bundle savedInstanceState) { StyleThemeTest.this.setTheme(R.style.theme1); super.onCreate(savedInstanceState); setContentView(R.layout.main); button1 = (Button) findViewById(R.id.button1); button2 = (Button) findViewById(R.id.button2); button3 = (Button) findViewById(R.id.button3); button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mDialog = new AlertDialog.Builder(StyleThemeTest.this) .setIcon(android.R.drawable.ic_dialog_alert) .setTitle("Warning!") .setMessage("Are you sure to Follow or UnFollow the friend?") .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Log.v(TAG, "OK"); } }) .setNeutralButton("Cancel",new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Log.v(TAG, "Cancale"); } }).create(); mDialog.show();// 如果要显示对话框,一定要加上这句 } }); button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Builder builder = new AlertDialog.Builder(StyleThemeTest.this); builder.setIcon(android.R.drawable.alert_dark_frame); builder.setTitle("AlertDialog Title."); builder.setMessage("What do think about this?"); builder.setNegativeButton("好", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Log.v(TAG, "good"); } }); builder.setNeutralButton("中立", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Log.v(TAG, "just soso"); } }); builder.setPositiveButton("不好", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Log.v(TAG, "bad"); } }); builder.create().show(); } }); button3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new AlertDialog.Builder(StyleThemeTest.this) .setMessage("There is a xxxxxxxxxxxx error hanppened!!!") .setPositiveButton("知道了!", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Log.v(TAG, "I KNOW."); } }).create().show(); } }); } }
发表评论
-
安卓自动编译工具Gradle
2015-09-02 15:15 1102https://developer.android.com ... -
图片的水平平铺效果
2014-03-10 15:45 2409Android要实现图片的水平平铺效果: 很简单也很强大, ... -
LinearLayout中的属性baselineAligned的使用
2013-10-19 18:54 34382Android线性布局中的属性主要的就是控制浮动方向的or ... -
Activity伪造Dialog的时候不能全屏显示
2013-05-31 08:42 14203使用Activity伪造Dialog的时候出现不能全屏的问 ... -
修改局部源码烧录手顺
2012-08-16 09:23 20961. 添加命令到PATH路径下,方便全局使用: andro ... -
备份我的源码烧录的sh文件
2012-07-16 10:39 1338烧录编译的img文件: 01.tofastboot.sh ... -
备份我的源码编译的sh文件
2012-07-16 10:34 1551编译命令写一次就可以了。以后直接使用。 01-extra_s ... -
ADT20安装报错
2012-06-29 23:44 9159Cannot complete the install bec ... -
ubuntu12.04(VirtualBox) 64-bit build android source
2012-05-20 17:33 29871.download VirtalBox(Virtual ... -
搭建android源码编译开发服务器
2012-05-20 17:32 72981.android服务器,其实也就是台式机器的增强版本。基本上 ... -
ADT离线安装报错
2012-04-23 09:37 3349最近使用ADT的离线zip包安装ADT总是报错。说是 Can ... -
Android源码编译中的Makefile文件
2012-04-18 09:09 24641.和大多shell文件一样,makefile中的#表示注释, ... -
遍历android根目录的简单资源查看器
2012-04-16 17:02 3702效果如图: package com.txl.sua; ... -
Nexus s与android4.0
2011-12-14 13:15 13871.内核源码链接 http://android.git.ke ... -
Android编译生成系统-译文
2011-12-08 11:21 3458生成 4.0.1 系统 下边 ... -
Android中设置TextView的颜色setTextColor
2011-11-10 11:34 182287android中设置TextView的颜色有方法setTex ... -
Android中设置activity的background为Wallpaper
2011-08-15 08:34 3859<activity android:name=&q ... -
android程序中怎么实现平铺效果
2011-08-10 17:06 4897很简单,就像window桌面图片一样,如果图片小的话就会平铺。 ... -
一个android应用向Home screen添加多个Widget
2011-08-09 15:12 5137如Twitter客户端或者HTC的日历应用,可以添加大小不 ... -
怎么实现Widget中的动画效果,如渐入等
2011-08-09 11:22 3033怎么在Widget中添加animation,如渐入渐出,淡入淡 ...
相关推荐
025_android UI组件之 AlertDialog 的各种实现,很细致的视频教程,这个可以学哦。。
Android中实现Iphone样式的AlertDialog.rar
026_android UI组件之 AlertDialog的自定义布局,很细致的视频教程,这个可以学哦。。
在Android中实现Iphone样式的AlertDialog; 使用Dialog实现。
android AlertDialog对话框的类型集合 ,比较全面的讲述了 AlertDialog 的 种类 , Demo 的综合性比较强 , Demo 可直接运行
Android高级应用源码-Android中实现Iphone样式的AlertDialog.zip
安卓Android源码——中实现Iphone样式的AlertDialog.zip
Android中实现Iphone样式的AlertDialog源码,是一个很不错的Android源码,有兴趣的伙伴们抽时间可以看一下把。
Android中使用AlertDialog的例子,包括简单提示框、单选提示框、多选提示框、自定义提示框、Activity和提示框的转换。
Android快速SDK(4)对话框AlertDialog
android 显示 AlterDialog
android AlertDialog使用例程 一个在安卓平台上开发使用AlertDialog的例子 很实用很全哦
Android入门第九篇之AlertDialog.docx
Android应用源码之Android中实现Iphone样式的AlertDialog.zip
Android之AlertDialog源码
android AlertDialog 单选 多选 输入框 疯狂android讲义
Android应用源码之Android中实现Iphone样式的AlertDialog.rar
1、从Activity的TextView中获取字符串设置到AlertDialog的TextView和EditText中 2、将AlertDialog的EditText中的值设置到Activity的TextView中 新手在自定义AlertDialog上的疑问笔者猜测主要有两个: 1、自定义的...
安卓Android源码——安卓Android中实现Iphone样式的AlertDialog.rar