Using android default buttons - android

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.

Related

Android - textview doesn't show up

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"

Does Android Studio Linter Offer An Option to look for default XML layout values?

1.) Is there any reason to have a default value inside an android xml layout?
Ex.) The TextView below has included a default value of
android:visibility="visible"
`<TextView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:visibility="visible"/>`
Conjecture: Because this is a default value, it has no effect, and therefore is an unnecessary line of code in the XML file. Is that line of thinking correct?
2.) If there is no reason for default values to exist in Android xml files, is there a lint plugin available to point out default value code lines in android XML files?
It is my thought that a large number of code lines in XML files are default values, serving no purpose. What can we do to reduce these lines of code?
U can create a style with your default values and use it.
For example:
<style name="DefaultTextViewStyle">
<item name="android:visibility">visible</item>
</style>
to use this:
<TextView
style="#style/DefaultTextViewStyle" />
I had some hope that the Lint inspection Redundant default value attribute assignment for xml, run via Android Studio might have done what you're asking. You can run it as specified under the Manually Run Inspections part of the Android docs. i.e.Android Studio -> Analyze -> Run Inspection by name -> enter "Redundant default value attribute assignment", then select the scope for the Lint check.
Sadly though, it doesn't pick up the case you mention above. I'm just wondering if there's something I've missed, or if this isn't intended for Android xml in some way?

error with fab button design with vector assets

I have used the dependencies to be used as suggested. below is the pic.
build_gradle(module)
now I have selected a black plus icon from vector assets and named it as fab_plus, now I have this file in my drawable folder.
fab_plus_XML
now I tried to used that fab_plus_XML like this. Pic below.
activity_main
Now my question is why is the fab_plus is showing in red.
thanks in advance. pls, help me, someone.
There are two things wrong with the way you are specifying the drawable. To refer to a drawable within your project, you simply use #drawable/your_drawable and to allow backward compatibility of VectorDrawables you should use app:srcCompat as per the guidance.
So in your ImageView, instead of
android:src="#android:drawable/fab_plus"
you should have
app:srcCompat="#drawable/fab_plus"
You will also need to make sure the app namespace is included at the top of your layout xmlns:app="http://schemas.android.com/apk/res-auto" along with the current android and tools namespaces.
you need to use:
app:srcCompat
instead of
android:src
but the tooltip there should exactly tell you this and AFAIR even offer a quick-fix

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.

Create plus and minus buttons like date picker

Is there a way to create a plus and minus button like the ones in the date picker dialog?
I mean without create them from scratch.
Thank you in advance.
One option is to do what Paresh mayani suggested.
You can set Background for your Button with android resource available. Datapicker uses a arrow up and arrow down resources available (android.R.drawable) . Instead of creating custom images and setting the same as a background to button, you can use the available ones. For list of all android drawables that you can use is available in the link below
http://developer.android.com/reference/android/R.drawable.html
To set the background programatically
Button b= (Button) findViewById(R.id.button1);
b.setBackgroundResource(android.R.drawable.arrow_up_float);
Set background in xml
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:drawable/arrow_up_float"
/>
Below are some links to resources that give you quick visuals of the android resources. I didn't see anything that exactly matches your needs, but maybe you can get a bit creative :) Don't forget to make sure to check version specifics if you are using them.
http://androiddrawableexplorer.appspot.com/
http://androiddrawables.com/buttons.html

Categories

Resources