Push an update. Chrome OS devices. App architecture. Architecture Components. UI layer libraries. View binding. Data binding library. Lifecycle-aware components. Paging Library. Paging 2. Data layer libraries. How-To Guides. Advanced Concepts. Threading in WorkManager. 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.
Control the system UI visibility. 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. Note that this works only for supported layout styles, so many themes in this list result in an error. Language : Select the language to show for your UI strings. This list displays only the languages available in your string resources.
If you'd like to edit your translations, click Edit Translations from the drop-down menu. You can create a new layout in one of the following ways: Use Android Studio's main menu In the Project window, click the module in which you want to add a layout. In the dialog that appears, provide the file name, the root layout tag, and the source set in which the layout belongs. Click Finish to create the layout. Use the Project view Choose the Project view from within the Project window.
Right-click the layout directory where you'd like to add the layout. Use the Android view Choose the Android view from within the Project window. Right-click the layout folder. Use layout variants to optimize for different screens A layout variant is an alternative version of an existing layout that is optimized for a certain screen size or orientation.
Use a suggested layout variant Android Studio includes common layout variants that you can use in your project. To use a suggested layout variant, do the following: Open your original layout file, click the Design icon in the top-right corner of the window.
Click Orientation for Preview in the toolbar. In the dropdown list, select a suggested variant, such as Create Landscape Variant. Create your own layout variant If you'd like to create your own layout variant, do the following: Open your original layout file, and click the Design icon in the top-right corner of the window.
In the dropdown list, select Create Other In the dialog that appears, define the resource qualifiers for the variant. Select a qualifier from the Available qualifiers list, and then click the Add button. Repeat this step to add other qualifiers as needed.
Once you've added all of your qualifiers, click OK. Convert a view or layout You can convert a view to another kind of view, and you can convert a layout to another kind of layout. Click the Design button in the top-right corner of the editor window. In the Component Tree , right-click the view or layout, and then click Convert view In the dialog that appears, choose the new type of view or layout, and then click Apply.
Convert a layout to ConstraintLayout For improved layout performance, you should convert older layouts to ConstraintLayout. To convert an existing layout to a ConstraintLayout , do the following: Open an existing layout in Android Studio, and click the Design button in the top-right corner of the editor window. In the Component Tree , right-click the layout, and then click Convert your-layout-type to ConstraintLayout. Find items in the Palette To search for a view or view group by name in the Palette , click the Search button at the top of the palette.
Add views to your layout To start building your layout, simply drag views and view groups from the Palette into the design editor. Tip: Extension classes can be defined as inner classes inside the activities that use them. This is useful because it controls access to them but isn't necessary perhaps you want to create a new public View for wider use in your application. Fully customized components can be used to create graphical components that appear however you wish. Perhaps a graphical VU meter that looks like an old analog gauge, or a sing-a-long text view where a bouncing ball moves along the words so you can sing along with a karaoke machine.
Either way, you want something that the built-in components just won't do, no matter how you combine them. Fortunately, you can easily create components that look and behave in any way you like, limited perhaps only by your imagination, the size of the screen, and the available processing power remember that ultimately your application might have to run on something with significantly less power than your desktop workstation. The onDraw method delivers you a Canvas upon which you can implement anything you want: 2D graphics, other standard or custom components, styled text, or anything else you can think of.
Note: This does not apply to 3D graphics. If you want to use 3D graphics, you must extend SurfaceView instead of View, and draw from a separate thread. This is made slightly more complex by the requirements of limits from the parent which are passed in to the onMeasure method and by the requirement to call the setMeasuredDimension method with the measured width and height once they have been calculated.
If you fail to call this method from an overridden onMeasure method, the result will be an exception at measurement time. At a high level, implementing onMeasure looks something like this:.
If you don't want to create a completely customized component, but instead are looking to put together a reusable component that consists of a group of existing controls, then creating a Compound Component or Compound Control might fit the bill.
In a nutshell, this brings together a number of more atomic controls or views into a logical group of items that can be treated as a single thing.
For example, a Combo Box can be thought of as a combination of a single line EditText field and an adjacent button with an attached PopupList. If you press the button and select something from the list, it populates the EditText field, but the user can also type something directly into the EditText if they prefer. In Android, there are actually two other Views readily available to do this: Spinner and AutoCompleteTextView , but regardless, the concept of a Combo Box makes an easy-to-understand example.
To summarize, the use of a Layout as the basis for a Custom Control has a number of advantages, including:. There is an even easier option for creating a custom View which is useful in certain circumstances.
If there is a component that is already very similar to what you want, you can simply extend that component and just override the behavior that you want to change. You can do all of the things you would do with a fully customized component, but by starting with a more specialized class in the View hierarchy, you can also get a lot of behavior for free that probably does exactly what you want.
As an example, the NotePad application demonstrates many aspects of using the Android platform. Among them is extending an EditText View to make a lined notepad. This is not a perfect example, and the APIs for doing this might change, but it does demonstrate the principles. If you haven't done so already, import the NotePad sample into Android Studio or just look at the source using the link provided. As always, the super is called first. Furthermore, this is not a default constructor, but a parameterized one.
The EditText is created with these parameters when it is inflated from an XML layout file, thus, our constructor needs to both take them and pass them to the superclass constructor as well. This example overrides only one method, onDraw , but you might need to override others as you create your own custom components.
For this sample, overriding the onDraw method allows us to paint the blue lines on the EditText view canvas the canvas is passed into the overridden onDraw method. The super. The superclass method should be invoked, and in this case, we do it at the end after we have painted the lines we want to include. We now have our custom component, but how can we use it? If your custom View component is not defined as an inner class, then you can, alternatively, declare the View component with the XML element name, and exclude the class attribute.
For example:. Notice that the LinedEditText class is now a separate class file. When the class is nested in the NoteEditor class, this technique will not work. And that's all there is to it. Admittedly this is a simple case, but that's the point — creating custom components is only as complicated as you need it to be.
A more sophisticated component may override even more on The only limit is your imagination and what you need the component to do. 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. Creating watch faces. Android TV. Build TV Apps.
Build TV playback apps. Help users find content on TV. Recommend TV content. Watch Next. Build TV games. Build TV input services. TV Accessibility. Android for Cars. Build media apps for cars. Close the SDK list window using 'Cancel'. Now you will be able to see "Events" just left of "Configure".
Click on it to see currently running installations. Hope it helps! How are we doing? Please help us improve Stack Overflow. Take our short survey. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?
Collectives on Stack Overflow. Learn more.
0コメント