Guide for custom UI controls

后端 未结 1 1371
独厮守ぢ
独厮守ぢ 2021-02-03 14:42

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

1条回答
  •  别那么骄傲
    2021-02-03 15:02

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

    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.

    • 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)

    • 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.

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

    • 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.

    0 讨论(0)
提交回复
热议问题