Reputation: 3485
I have a problem whose solution I am unable to find out. I am creating an imagebutton thorugh Android SDk and although it shows in Preview window it does not show in Nexus 6 Emulator. The image is attached here
Code for xml file is
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp"
tools:context=".ViewActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="@dimen/activity_bold_textsize"
/>
<ImageButton
android:id="@+id/imageButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:src="@tools:sample/avatars" />
<CheckBox
android:id="@+id/checkBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/rememberMe" />
<RadioGroup
android:id="@+id/radio_g1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/rad1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rad1"/>
<RadioButton
android:id="@+id/rad2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rad2"
/>
</RadioGroup>
<ToggleButton
android:id="@+id/toggleButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/togb1" />
<Switch
android:id="@+id/switch1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/Switch" />
</LinearLayout>
Upvotes: 1
Views: 945
Reputation: 3391
Cause of, You are used tools:src
attribute instead of android:src
.
tool:<attributes>
= Working only in preview emulator. It just show you Temporary hint.
android:<attributes>
= Used for the actual definition that you have defined
for Ex. If you use tool:text
within textView. It's only shown like hint as how looks applied theme.
Upvotes: 0
Reputation: 1111
You do not known the diffenrence between tools
and android
.
tools:src="@tools:sample/avatars"
is only show on preview of IDE.
Change to
android:src="@tools:sample/avatars"
Check the document: https://developer.android.com/studio/write/tool-attributes
Upvotes: 3