I've written a tiny library that allows you define design-time attributes for your views: https://github.com/paulmanta/app-tools-attrs
Firstly, you have to declare separate attributes that you want to as at design-time:
<declare-styleable name="MyWidget">
<attr name="title" format="string"/>
<attr name="tools_title" format="string"/>
</declare-styleable>
Finally, when you initialize your custom view use the AppToolsAttrs
class instead of accessing attributes directly from a TypedArray
:
AppToolsAttrs.getString(a, isInEditMode(), R.styleable.MyWidget_title, R.styleable.MyWidget_tools_title)
You can then use your design-time attributes like this:
<com.myapplication.MyWidget
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tools_title="Lorem ipsum"
app:title="@string/real_title"/>
Gil already posted an answer with a different library that allows you do this. His implementation is really smart and it allows you to use the actual tools:
namespace without having to duplicate attributes. Unfortunately, it's incompatible with Android Studio's auto-complete feature.