1.Drawable的使用

android.graphics.drawable

Most often you will deal with Drawable as the type of resource retrieved for drawing things to the screen; the Drawable class provides a generic API for dealing with an underlying visual resource that may take a variety of forms.

最经常会处理Drawable作为类型的资源回收绘制到屏幕上的东西; Drawable类提供了一个通用的API来处理一个基本的视觉资源,可以采取多种形式。(讲的有点抽象)讲白点就是获取res下的参数

例:改变TextView文字颜色-引用Drawable颜色常熟及背景色

values下的color.xml

  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. <resources>
  3. <drawablename="darkgray">#808080FF</drawable>
  4. <drawablename="white">#FFFFFFFF</drawable>
  5. </resources>

对文本框的背景色进行设置


  1. Resourcesresources=getBaseContext().getResources();
  2. DrawableHippoDrawable=resources.getDrawable(R.drawable.white);
  3. mTextView01.setBackgroundDrawable(HippoDrawable);

2.获取手机屏幕大小

  1. DisplayMetricsdm=newDisplayMetrics();
  2. getWindowManager().getDefaultDisplay().getMetrics(dm);
  3. Stirngwidth=dm.widthPixels;
  4. Stirngheiht=dm.heightPixels;


3.Android style 机制

仅仅是加了一个Style. 一个Style就能够实现控件的显示效果样式么?Android的Style机制真的很强大.
例:

  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. -<resources>
  3. -<stylename="DavidStyleText1">
  4. <itemname="android:textSize">18sp</item>
  5. <itemname="android:textColor">#EC9237</item>
  6. </style>
  7. -<stylename="DavidStyleText2">
  8. <itemname="android:textSize">14sp</item>
  9. <itemname="android:textColor">#FF7F7C</item>
  10. <itemname="android:fromAlpha">0.0</item>
  11. <itemname="android:toAlpha">0.0</item>
  12. </style>
  13. </resources>


  1. <?xmlversion="1.0"encoding="utf-8"?>
  2. -<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:background="@drawable/white"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent">
  3. -<!--应用模式1的TextView
  4. -->
  5. <TextViewstyle="@style/DavidStyleText1"android:layout_width="fill_parent"android:layout_height="wrap_content"android:gravity="center_vertical|center_horizontal"android:text="@string/str_text_view1"/>
  6. -<!--应用模式2的TextView
  7. -->
  8. <TextViewstyle="@style/DavidStyleText2"android:layout_width="fill_parent"android:layout_height="wrap_content"android:gravity="center_vertical|center_horizontal"android:text="@string/str_text_view2"/>
  9. </LinearLayout>

更多相关文章

  1. 用 Kotlin 开发现代 Android(安卓)项目 Part 2
  2. 一点见解: Android事件分发机制(一)
  3. [Android实例] Android(安卓)开发者面试题-广播机制详解
  4. android 事件流转机制
  5. 【Android】注解框架(二)-- 基础知识(Java注解)& 运行时注解框架
  6. Android使用Thread+Handler实现非UI线程更新界面
  7. ELIPS Studio 3 Beta 6支持iPhone和Android原生服务
  8. 获取 Android(安卓)4.2 的 ROOT 权限(越狱)
  9. 获取Android(安卓)设备信息——build.prop

随机推荐

  1. 关于 Android 异步消息处理机制 Handler
  2. Android - Session 'app': Error Install
  3. 2017年Android面试题总结
  4. android音乐播放器拖放播放进度设计
  5. Android 实现动态生成菜单
  6. Android(安卓)文字倾斜
  7. android 定时任务的几种实现方式
  8. 一些android porting 例子
  9. 禁止应用获取手机信息
  10. Android程序运行中动态加载Lib的方法(一)