导自定义UI控件 [英] Guide for custom UI controls

查看:94
本文介绍了导自定义UI控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开发一个Android应用程序,但我不希望使用默认控件(按钮,复选框,单选按钮等)。有什么办法可以自定义这些控件使其出现更好。如果是这样的一些教程或指南将帮助我很多。谢谢....

I want to develop an android application, but i dont want to use the default controls(buttons, checkboxes, radio buttons, etc.,). Is there any way to customize those controls to make it appear nicer. If so some tutorial or guide will help me a lot. Thanks....

推荐答案

如果你想创建全新的UI元素,你应该阅读的在创建自定义组件开发人员指南主题/景观

If you want to create completely new UI elements, you should read the developer guide topic on creating custom components/views.

如果,在另一方面,你只是想改变现有的用户界面元素的外观,下面是这就是你需要做的不完全名单。这里假设你已经熟悉了的Andr​​oid资源框架和布局系统。

If, on the other hand, you simply want to change the appearance of existing UI elements, below is a non-exhaustive list of things you'll need to do. This assumes you're familiar with the Android resources framework and layout system.

  • 首先,看看它们是如何在Android源$ C ​​$ C实现的( AOSP ,的 GitHub的镜子)。所有code,你感兴趣的是在框架/ base.git 项目(快速链接:资源,<一个href="https://github.com/android/platform_frameworks_base/tree/master/core/java/android/widget/">Java来源的)

  • First, see how these are implemented in the Android source code (AOSP, GitHub's mirror). All of the code you're interested in is in the frameworks/base.git project (quick links: resources, Java sources)

对于每种类型的UI元素,打造九补丁PNG可绘制为每个UI状态(pssed默认情况下,禁用$ P $,突出重点等),并为每个相关密度(如中,高,超高密度)。这些PNG图像应该在你的 RES /绘制-MDPI / RES /绘制 - 华电国际/ RES /绘制-xhdpi / 目录。

For each type of UI element, create Nine Patch PNG drawables for each of the UI states (default, disabled, pressed, focused, etc.) and for each relevant density (e.g. medium, high , and extra-high densities). These PNGs should be in your res/drawable-mdpi/, res/drawable-hdpi/, and res/drawable-xhdpi/ directories.

对于每种类型的UI元素,营造状态列表XML绘制&LT;选择&GT; ),这将是你的 RES /绘制/ 目录。国家列表绘制为默认的Andr​​oid按键可以发现<一href="https://github.com/android/platform_frameworks_base/blob/master/core/res/res/drawable/btn_default.xml">here.

For each type of UI element, create a state list XML drawable (<selector>), which will be in your res/drawable/ directory. The state list drawable for the default Android push button can be found here.

设置你的按钮/文本/等的安卓背景属性状态列表绘制的名字。例如,属性值应 @绘制/ myButton的如果您的国家列表绘制为 RES /绘制/ mybutton.xml

注意:您可以使用主题以减少冗余(即保持干燥)的XML文件。

Set your button/textbox/etc.'s android:background attribute to the state list drawable name. For example, the attribute value should be @drawable/mybutton if your state list drawable is res/drawable/mybutton.xml.

Note: You can use themes to reduce redundancy (i.e. keep them DRY) in your XML files.

这篇关于导自定义UI控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆