Custom text to view spinner in android graphics editor

By default, if I create a Spinner in the graphic layout editor (using the Spinner Item preview layout, i.e. android.R.layout.simple_spinner_item ), the displayed text

Paragraph 1

Is there any way to change this preview text?

+6
source share
3 answers

Views have a function called "isEditMode ()" that can be used to change the way elements are displayed in a graphics editor. This SO can help you:

Android Custom Views in the Visual Eclipse Visual Editor

+2
source

In particular, to preview the spinner, use tools:listitem along with the layout:

 <Spinner android:id="@+id/spinner1" android:layout_width="wrap_content" android:layout_height="wrap_content" tools:listitem="@android:layout/simple_list_item_1" /> 

You can also set this preview in the visual editor by right-clicking on the Spinner and selecting "Preview layout spinner". In any case, it should be a specific layout, not a simple text string.

Thus, it is recommended that you install fictitious texts in a specific layout of the list item that you will use anyway (for example, in your Adapter in Java code), and then directly view this layout, as described above.

+14
source

First you need to create an appropriate preview layout. For example, you can put this in layout / preview.xml:

 <?xml version="1.0" encoding="utf-8"?> <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" style="?android:attr/spinnerDropDownItemStyle" android:singleLine="true" android:layout_width="match_parent" android:layout_height="?android:attr/listPreferredItemHeight" android:text="NEW PREVIEW TEXT" android:ellipsize="marquee" /> 

Then you can right-click Spinner in your actual layout and select Spinner Preview Layout> Select Layout ... Select a layout from the project resources and you will see a new preview.

You can also set the preview layout in XML format with tools:listitem="@layout/preview"

+11
source

Source: https://habr.com/ru/post/1469517/


All Articles