Constant Value: 0xaa. Constant Value: 0xab. Constant Value: 0xa7. Constant Value: 0xa8. Drawable to use as a background for a taller version of the titlebar. Constant Value: 0xa6. Except as noted, this content is licensed under Apache 2. For details and restrictions, see the Content License. From class java. App entry points. App shortcuts. App navigation. Navigation component.
App links. Dependency injection. Core topics. App compatibility. Interact with other apps. Package visibility. Intents and intent filters. User interface. Add motion to your layout with MotionLayout. MotionLayout XML reference. Improving layout performance. Custom view components. Look and feel. Splash screens. Add the app bar. Window insets. Supporting swipe-to-refresh. Pop-up messages overview. Adding search functionality. Creating backward-compatible UIs. Home channels for mobile apps.
App widgets. Media app architecture. Building an audio app. Building a video app. The Google Assistant. Routing between devices. Background tasks. Manage device awake state.
Save to shared storage. Save data in a local database. Sharing simple data. Sharing files. Sharing files with NFC. Printing files. XML drawables are used to describe shapes color, border, gradient , state, transitions and more. Drawables can also be written in Java code. Every object which implements Drawable can be used as a Drawable in code. In code you can also assign drawables to views. Most views accept an resource ID as input parameter. For example the following code shows how to set a drawables as background to an ImageView.
Android allows you to use the Bitmap class for working with bitmaps. This section explain how to create Bitmap objects via Java code and how to convert Bitmap into Drawable objects and vice versa. If required you can load any accessible bitmap file in your code and convert them into Drawables objects. The following example code shows how to create an Bitmap object for the assets folder and assign it to an ImageView.
The following code demonstrates that. To convert a Bitmap object into a Drawable you can use the following code. Shape Drawables are XML files which allow to define a geometric object with colors, borders and gradients which can get assigned to Views. The ShapeDrawable class, like many other drawable types in the android. Some example properties you might want to adjust include alpha transparency, color filter, dither, opacity, and color. You can also define primitive drawable shapes using XML resources.
For more information, see Shape drawable in Drawable resource types. A NinePatchDrawable graphic is a stretchable bitmap image that you can use as the background of a view. Android automatically resizes the graphic to accommodate the contents of the view. An example use of a NinePatch image is the background used by standard Android buttons—buttons must stretch to accommodate strings of various lengths.
It must be saved with the 9. Use the border to define the stretchable and static areas of the image. You indicate a stretchable section by drawing one or more 1-pixel wide black line s in the left and top part of the border the other border pixels should be fully transparent or white.
You can have as many stretchable sections as you want. The relative size of the stretchable sections stays the same, so the largest section always remains the largest. You can also define an optional drawable section of the image effectively, the padding lines by drawing a line on the right and a line on the bottom. If a View object sets the NinePatch graphic as its background and then specifies the view's text, it stretches itself so that all the text occupies only the area designated by the right and bottom lines if included.
If the padding lines aren't included, Android uses the left and top lines to define this drawable area. To clarify the difference between the lines, the left and top lines define which pixels of the image are allowed to be replicated in order to stretch the image.
The bottom and right lines define the relative area within the image that the contents of the view are allowed to occupy. This NinePatch graphic defines one stretchable area with the left and top lines, and the drawable area with the bottom and right lines. In the top image, the dotted grey lines identify the regions of the image that are replicated in order to stretch the image.
The pink rectangle in the bottom image identifies the region in which the contents of the view are allowed. If the contents don't fit in this region, then the image is stretched to make them fit. It even raises warnings if the region you've defined for the stretchable area is at risk of producing drawing artifacts as a result of the pixel replication.
Notice how the width and height of the button varies with the text, and the background image stretches to accommodate it. When you want to create some custom drawings, you can do so by extending the Drawable class or any of its subclasses. The most important method to implement is draw Canvas because this provides the Canvas object you must use to provide your drawing instructions.
The following code shows a simple subclass of Drawable that draws a circle:. Then you can add your drawable wherever you'd like, such as to an ImageView as shown here:.
On Android 7. You can tint them with color resources or theme attributes that resolve to color resources for example,? Usually, you create these assets only once and color them automatically to match your theme. You can also set the tint color and mode in your layouts with the android:tint and android:tintMode attributes. The Android Support Library includes the Palette class, which lets you extract prominent colors from an image.
You can load your drawables as a Bitmap and pass it to Palette to access its colors. Content and code samples on this page are subject to the licenses described in the Content License. App Basics. Build your first app. App resources. Resource types. App manifest file. Device compatibility. Multiple APK support. Tablets, large screens, and foldables. Build responsive UIs. Build for foldables. Getting started. Handling data.
User input. Watch Face Studio. Health services. Develop with Godot. Develop with Unity. Use Android Performance Tuner. Game best practices. Maximize device availability. Art assets. OpenGL and Vulkan. Game Mode. Best practices. Building effective unit tests. Automating UI tests. Testing app component integrations. Android Vitals. Optimizing for Battery Life. System tracing.
Build and test apps for accessibility. Advanced topics. Protecting against security threats with SafetyNet. Build for Billions. Build for Enterprise. App feedback. Device management. Dedicated devices. Android versions. Android Developers. There are several different types of drawables: Bitmap File A bitmap graphic file. Creates a BitmapDrawable. Creates a NinePatchDrawable. Layer List A Drawable that manages an array of other Drawables.
These are drawn in array order, so the element with the largest index is be drawn on top. Creates a LayerDrawable. State List An XML file that references different bitmap graphics for different states for example, to use a different image when a button is pressed.
Creates a StateListDrawable. Level List An XML file that defines a drawable that manages a number of alternate Drawables, each assigned a maximum numerical value. Creates a LevelListDrawable. Transition Drawable An XML file that defines a drawable that can cross-fade between two drawable resources. Creates a TransitionDrawable.
Inset Drawable An XML file that defines a drawable that insets another drawable by a specified distance. This is useful when a View needs a background drawable that is smaller than the View's actual bounds. Creates a ClipDrawable. Scale Drawable An XML file that defines a drawable that changes the size of another Drawable based on its current level value. Creates a GradientDrawable. Bitmap A bitmap image. Bitmap file A bitmap file is a. Kotlin val shape: Drawable? Place the object in the center of its container in both the vertical and horizontal axis, not changing its size.
Grow the horizontal and vertical size of the object if needed so it completely fills its container. This is the default. The clip is based on the vertical gravity: a top gravity clips the bottom edge, a bottom gravity clips the top edge, and neither clips both edges. The clip is based on the horizontal gravity: a left gravity clips the right edge, a right gravity clips the left edge, and neither clips both edges.
Repeats the shader's image horizontally and vertically, alternating mirror images so that adjacent images always seam. Put the object at the top of its container, not changing its size. When clipOrientation is "vertical" , clipping occurs at the bottom of the drawable.
0コメント