New XML Refactorings for Android Developers
Recently, we’ve added a number of new refactorings for Android XML layout files. All the refactorings can be used right in the editor, in the UI designer (from “Design” panel or “Component Tree”) or can be invoked from the Structure View.
So, here’s what we’ve prepared for you:
- Extract Style. Styles in Android is an analogue of cascading stylesheets in web design — they allow you to separate the design from the content. With this new refactoring you can create a new style from a layout XML tag. To perform refactoring just place the caret into an XML tag and choose Refactor | Extract | Style… from a popup menu in XML editor or Refactor | Extract Style… in the UI designer. Moreover, it is possible to extract parent style from an existing style declaration.
- Inline Style. Sometimes you need to perform the reverse operation: add all the attributes defined in a style to the components it is applied to (all or one of) or merge parent style with its inheritor. To perform such refactoring place the caret into style declaration of some component the style applied to and choose Refactor | Inline Style… from the pop-up menu. Also, you can use common “Inline…” action of the IDE, just place the caret into “@style/…” reference and press Ctrl+Alt+N (Or Meta+Alt+N on Mac). In the UI designer the refactoring can be invoked by choosing Refactor | Inline Style…
- Extract Layout. In Android it is possible to re-use your layouts using <include> tag. With this refactoring you’re able to move a part of your existing layout to separate xml file and insert <include> tag instead. To do it, select one or more elements in your layout and choose Refactor | Extract | Layout… from the pop-up menu. In UI designer mode the refactoring can be invoked from Refactor | Extract layout…
- Inline Layout. This refactoring allows you to inline some included layout and remove <include> tag. To do this, choose an included file in Project View or place the caret to the “@layout/…” reference and press Ctrl+Alt+N. As well as other refactorings, this one is also available from the pop-up menu in UI designer.
Tip: One good way to invoke all these and other refactorings is the ‘Refactor This’ popup (Refactor | Refactor This… from the menu). Remember its hotkey and you have them all.
Reminder: All Android-related functionality is available in free IntelliJ IDEA Community Edition.
You’re welcome to try these features in the latest IntelliJ IDEA 12 EAP and let us know what you think.
Subscribe to Blog updates
Thanks, we've got you!
The What, Why, and How of JPA Buddy in IntelliJ IDEA
Master JPA entity management with JPA Buddy in IntelliJ IDEA! Our latest article shows you how to simplify your workflow and reduce boilerplate code.
The Best of IntelliJ IDEA’s HTTP Client
In today's fast-paced tech world, easy and efficient management of web services and APIs is crucial. That's where IntelliJ IDEA's HTTP Client steps in, turning complex HTTP requests into a walk in the park. The HTTP Client is a feature-rich, text-based tool in IntelliJ IDEA Ultimate. It seamlessl…
Import Postman Collections to the HTTP Client
We know that many of you use Postman collections and want to stay in the flow while working with them. This means staying inside IntelliJ IDEA and not switching to a different app. Great news! You can now effortlessly transform Postman collections into .http and use them in the HTTP Client …
What’s New in IntelliJ IDEA 2023.1 for Spring Developers
The IntelliJ IDEA 2023.1 release came packed with updates for Spring. This blog post will highlight the most noticeable changes, including full support for Lombok, a reworked Spring tool window, navigation for Spring Security rules, Spring Security 6 support, and more. Remember that these featur…