Android - textview doesn't show up - android

For some reason, my textview Add a base doesn't show up when I launch the app on my phone. I have no idea why, 'cause it is displayed on Android studio :O

Replace tools:text="#string/add_base" with android:text="#string/add_base"
Attributes in the tools namespace are shown only when designing layouts. When you build your app, the build tools remove these attributes so there is no effect on your APK size or runtime behavior.
Reference: https://developer.android.com/studio/write/tool-attributes

tools:text="YOUR TEXT" can be used for your design and preview purpose.
If you add any text as a tools:text app will not use this text as that is not the actual text that should be rendered on the app
So instead of this, you should use android:text="YOUR TEXT"

Related

Prevent android studio to create more than a tag in xml files

In the new android studio 3.3 or 3.2 if we create a for example button auto generate create a text like
<Button android:layout_width="" android:layout_height=""/>
but I would like something more like this
<Button
android:layout_width=""
android:layout_height=""/>
like old versions of Android studio is there a setting or something for that?
That is related to XML code wrapping. By default it should be on wrap always but maybe it's not in your Android Studio or they changed that in newer versions. Anyway you can find that by click on:
Preferences -> Code Style (expand it) -> XML -> Android(Tab) ->
Here you can find Layout Files and below options like: Wrap always, Don't wrap, Wrap if long etc. So set it on Wrap always and Apply changes and your XML code from now on should be wrapped.
It hints something that says reduce intent with 4 spaces. Try to configure that :)
Or use the hard way by pressing enter for the new row.

In Android Studio, set android:text from strings.xml, but back to text later

I set android:text like below
android:text="#string/app_name"
But it will be changed to the following format later.
android:text="TestApp"
How to resolve it in Android Studio?
Many thanks!
This is a feature of android studio. It looks up the value of the resource and previews it for you so you don't have to go to the resource file and look it up manually.
It is only a visual preview. It does not affect your code/xml in any way.

Autoinsert right-to-left attributes Android Studio

I don't know all features of Android Studio, I have tried to search,but found nothing.
I wonder if it is possible to make Android Studio autoinsert attributes required for right-to-left support.
For example I have typed following line
android:layout_marginLeft="10dp"
Is it possible to make Android Studio insert marginStart attribute automatically ?
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
And vice-versa(for padding too).
This would save some time.
Maybe someone knows how to get such behavior, I will be grateful for any help. Thx.
Apparently, you can't do that. You have to write them yourself.
The difference between layout_marginLeft and layout_marginStart for example is that layout_marginLeft is executed for left to right languages like English, while `layout_marginStart' is only executed for right to left languages like Arabic.
So if you are going to add string translations to your app including arabic or any other right to left languages, you will need to write marginStart or marginEnd attributes... So anyway, if you didn't write layout_marginStart for example and your app doesn't support Arabic language or any other right to left languages, no error will occur to the user; it is just a warning that Android Studio tells you.
Definitely the same concept is applied to padding attributes. Hope that helps you.
Edit:
If you don't like to see Android Studio warning you these warnings, you can simply disable that by clicking on the yellow light bulb beside the yellow highlighted warning and selecting Edit 'Using left/right instead of start/end attributes' inspection settings, then uncheck it from the list.
But if you don't want to change the inspection settings, you can just add the following to your View that you don't want to use start/end attributes in it:
tools:ignore="RtlHardcoded"
and add that to your parent layout that contains that View:
xmlns:tools="http://schemas.android.com/tools"

Using android default buttons

I found these website http://androiddrawables.com/Buttons.html where you can check the differences between Android buttons .
How can I use them? If I type R.drawables.btn_star_big_on_pressed the editor says it couldn't find the resource.
How can I use those default Android images ?
I am using 4.0.
The only way I know how to use them is:
<ImageView
android:id="#+id/imageView"
android:layout_width="48px"
android:layout_height="48px"
android:src="#android:drawable/btn_radio" />
to check available buttons type first letter after drawable/.
Then navigate to the button and you will see the selectors.
You can do something like this,
android.R.drawable.btn_star
Default resources for UI components depend on the device and platform version that your app is running on. For your button's to use them you would want to simply not declare a background resource.
My advice is that you will go to the Android SDK folder/platforms/android-##/data/res/drawable-dpi and copy the icons from there into your own res folder.

Can you set graphical layout preview-only text on a TextView?

I have a styled TextView whose real text is populated dynamically at runtime. The Graphical Layout view is very useful for getting a feel on how this component works with others in terms of look and feel, etc. There is no sensible default to this text field and I wish it to be blank before being populated. If I don't specify any text in the TextView declaration then the TextView is blank. I can set the text manually using:
<TextView
...
android:text="Preview text"/>
and then switch to the Graphical Layout. However, I must remember to remove this or risk it being shipped in my production version.
Is there a way to specify text which is only seen in the Graphical Layout preview but not applicable at runtime?
EDIT: I'm using Eclipse ADT.
Yes you can with the design tools extension attributes in Android Studio.
See this page https://developer.android.com/studio/write/tool-attributes.html
Basically you define the tools namespace
xmlns:tools="http://schemas.android.com/tools"
Then use it to set your placeholder text.
<EditText
tools:text="John Doe"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
This actually works with most (if not all xml attributes).
e.g
tools:visibility="gone"
would set the preview visibility to "gone" but the runtime visibility would be unchanged.
I don't believe there is, the only possible way is when you declare your TextView, you say after, tv.setText(""); this way you will always find it blank at runtime

Categories

Resources