AndroidStudio Adding an image to draw with srcCompat - android

I am trying to do a drawer activity with Android Studio and I'm wanting to personalize the icons used. I've downloaded the icons I want to use and for the most part, it's okay.
In fact, I can modify all the android:icon icons but I have no idea how to modify the app:srcCompat icons. I don't know how to detect the image I want to use in this case...
Do you know how I can do it? Could you explain this to me?
Thanks a lot!
Edit: The file I'm working on as a base is the generated project with Drawer activity as the main activity. For example, if I wanted to modify the icon in the nav_header_main.xml file, how could I do to have my image (.png) transformed in a way detected by Android Studio as compatible with srcCompat

Ensure your image file is in res/drawable folder(or drawable-xhdpi/xxhdpi, determined by your design)
Refer it by app:srcCompact="#drawable/$IMAGE_FILE_NAME" in your xml.
Then you should see what you want.
Please check the doc to further understand the official usage.

Well... I was blind! I was wondering how I could add my icons but they were, I was just mistaking on the address... #android:drawable/... is obviously not #drawable/... but I didn't notice. So be aware that there is a difference and it'll be okay I think!

Related

Background not show in LinearLayout in version 4.2

my problem is that in version 4.2 the background in LinearLayout not showing, but in previous version it showing. I put the background like this:
android:background="#drawable/image"
I don't understand why.
I was just having the exact same problem. What fixed it for me was making sure I had the proper versions in the proper drawable-xxxx folder. For example...
If your image is in res/drawable but not in any other folder like res/drawable-hdpi, res/drawable-xhdpi, etc make sure you create a version appropriate for each of the screen sizes you are supporting and include that version in the corresponding drawable folder.
After I did that my bg drawable started showing up.
maybe it helps someone..I had a problem too with version 4.1.1 and everything I do was to set background programmatically
myLayout.setBackground(yourDrawable);
There isn't any problem with the syntax you are using. May be you are having some other problem. My advice would be to-
Try cleaning the project and run it again.
Check if you have the image named 'image.xxx' in your drawable folder.
Check if you are setting background of the correct layout.
or perhaps you can post some more code so that we can answer you more specifically.
Adding to the Above answer, check that the name of the image in drawable folder is in lower-case. All the drawables must have lower-case names.

how to make ICS like tabs (white background with sky blue line at the bottom) in android 2.2

How Do I make deafult ICS style tabs in android 2.2. I don't want to use ActionBarSherlock, instead I need to apply custom drawables. Can someone help ?
I tried using 9.png but didn't help much, as it didn't fill the complete tab, instead it shows only some blurred extended background. If you are suggesting some drawables - Please provide the drawable as well.
You can download ready made demo from this link: ICSStyleTab. I tried it for one of the project and it is working fine. If you wanted to add pager functionality, you can easily add using FragmentPager from Support V4 Library.
Update: ICSStyle Tab With Pager Demo
Thanks.
HoloEverywhere is a library to provide ICS/Holo theme to pre-3.0 devices:
https://github.com/Prototik/HoloEverywhere
Even if you really want to write your own code, you can gain a great deal of insight simply by looking into its source.

Choosing Drawable to show on a imageview programmatically

I have say N images that i want to include in my android project resources, say image0 to imageN-1, how do I set an image view to show one of those drawables say imagei when i is known only at runtime?
something like that:
imageView.setImageDrawable(getResources().getDrawable("R.drawable.image"+i));
obviously that wouldnt work but you know what i mean...
Thanks!
You can use Resources.getIdentifier() as in this blog explained

Styled Toggle Buttons in Android

I was reading the tutorial on Styling the Android toggle button here. The author asks us to create the 9patch drawable for both. I have trying to do this all morning, but have not been able to. Could anyone share the images with me, or tell me where i can get them ?
Kind Regards
You can find the 9patch drawable tool in the SDK folder in the tools folder.
It's a very useful tool for creating 9patch images, and you should be able to make your toggle button with it
There are links to 9-patches here: https://stackoverflow.com/a/15640365/2066079
The ones provided will style your togglebuttons to look like switches (which are only available in v14+)

How do I customize the look & feel of a Gallery?

I'm having a hard time understanding how I can create my own Gallery item. Specifically, I want to alter the appearance of the rectangle that surrounds whatever is the currently selected item (and remove altogether the rectangle that surrounds the non selected items).
Is there a good tutorial on how to create my own styles and pass them into my Widgets?
[Edit]
When initializing my gallery I hand it this
R.styleable.GalleryTheme_android_galleryItemBackground
and
R.styleable.GalleryTheme
I'm sure if I could crack those open, I could then copy and alter into what I want.... but where does Android store these?
[/edit]
The contents of those themes can most likely be found some where in the source code of the Android Open Source Project. It'l probably be somewhere here in the resources folder
Ok... this thread answers the actual question:
Android Hello, Gallery tutorial -- "R.styleable cannot be resolved"
Hope it helps someone.

Categories

Resources