I Just know that we can use fonts for text only by using the TypeFace class. But can anyone please confirm me about images.
I have added all my custom fonts(.ttf) inside asset/fonts folder. Placed some ImageViews in their appropriate place in my app. And trying to use fonts to set images on them.
I have googled for a long time, but unfortunately unable to find any satisfied hint or help.
Can any one please help me to go forward from the current step.
Placed some ImageViews in their appropriate place in my app. And trying to use fonts to set images on them.
ImageView accepts images. Whatever set of pixels or vectors are in a font, they are not images from the standpoint of ImageView. The simplest way to display material from a custom font is through TextView, though you are welcome to implement your own Drawable and attempt to use that with an ImageView, or draw straight to the Canvas (e.g., in a custom widget).
You can use font awesome. Import the android-iconify/1.0.6 jar library from http://repo1.maven.org/maven2/com/joanzapata/android/android-iconify/1.0.6/
and you can use IconTextView
<IconTextView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:padding="10dp"
android:text="{fa-mobile}"
android:textColor="#9fd46c"
android:textSize="30dp"
/>
Related
I want to create icons as something like this image or something like on the homepage of quickr. If I use custom gridview for this as in this (of course in my case I need the text below the image ), then adding listeners to that would be difficult I guess. Should I use buttons for that with the image and text below that provided the background is transparent? If so which layout I need to use? Or is there any icon view facility in android like other views such as button and imageviews, so that we can modify as per our requirement.
You should use button for that.
<Button
android:id="#+id/btnIconName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/iconimage"
android:text="IconTitle" />
For showing icon you should use android:drawableTop and for iocnTitle use android:text
Property.
I hope my answer is helpful to you.
GridView will be the best option to do this and why dont you ask your graphics guy to add text with image.
There is no setBackground() method in the RemoteViews class, so I've used the following workaround:
Created a FrameLayout for my app widget with an ImageView as the background view.
Changed the ImageView image using setImageViewResource() method.
Unfortunately, when it comes to 9-patch drawables this method does not work. Also when an ImageView's android:src attribute points to 9-patch - it doesn't work too. Is there any way to change the AppWidget's background image programatically using a 9-patch drawable? Thanks in advance.
EDIT
Settings the 9-patch as initial background in the XML:
<ImageView
android:id="#+id/small_widget_layout_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background_lime" />
When I use android:src="#drawable/background_lime" it doesn't stretch the image properly, this code works fine. And the code to change the background from the AppWidgetProvider onUpdate method:
views.setImageViewResource(R.id.small_widget_layout_bg,
R.drawable.backgroung_lime);
This does not stretch the image as a 9-patch.
This answer was diagnosed in the above comments...
RemoteView doesn't allow access to View.setBackground(), so your workaround of using the android:src property of an ImageView is good, providing that the android:scaleType property is set to fitXY.
ImageView won't stretch it's foreground image unless you tell it to.
Please ignore if u find this trivial or irrelevant, but canT you try (assuming you are dealing with widgets):
Declaring different layouts (xml)for your widget.
Change the remoteView's source (layout.id) instead of trying to make alterations to the selected layout.
AFAIK, this is the most common approach to solving such problems. This is not perfect for two simple things I could note myself:
What do you do if you have n different "states" / "views" in your widget?
But as long as your 9-patch files are also static resources, n is painful but still theoretically manageable.
It s tedious to keep track of the changes in these parallel files.
I'd also love to find an easy way for this one...
This approach may not be an option for you also because it is basically the hard way. But it s an option nonetheless.
Suggestion #2
Have you tried using the method?
public void setInt (int viewId, String methodName, int value)
remoteView.setInt(R.id.viewid, "setBackgroundResource", R.drawable.backgroung_lime);
From another question: Change remoteView ImageView background
I am designing something that will have a homepage close to the Google+ android app.
I'm having trouble figuring out the best way to do this? Should I create a button with text and set the background as the image? Should I create an image with the text already programmed in the actual picture or should I program the text and picture to be buttons.
Any suggestions from you guys on past projects?
You can use a Button with text to whatever you like and then place the image for that button above the text (using android:drawableTop)like so:
<Button
android:id="#+id/imageButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Photos"
android:drawableTop="#drawable/button_image" />
replacing buttton_image with your actual image. If you want the image in a different position (i.e. below text etc) use:
android:drawableLeft
android:drawableRight
android:drawableBottom
This would be how I would and do do it...
Since I am a newbie in android development I may be wrong but I suggest why not use a Grid View with each grid item haaving a textview and imageview.
My suggest to layout:
If you want to try something new in Android 4.0 , you can try GridLayout to layout , it can reduce the complicate of the nested layout , check out the blog about GridLayout:
http://android-developers.blogspot.com/2011/11/new-layout-widgets-space-and-gridlayout.html
You should write Buttons this way: http://developer.android.com/resources/articles/layout-tricks-merge.html
I normally use RelativeLayout but this is not important.
Write a class myClass extends RelativeLayout and inflate the XML with
LayoutInflater.from(context).inflate(R.layout.myCustomLayout, this, true);
I think this is best practice by Google.
use a regular button and set the android:drawableTop="#drawable/icon_...." value
Having the text burnt into you image is most certainly not the way to go.
One option for you is a GridView. You could also do this through a combination of Image button and scrollview. In my opinion, GridView is best and involves the least amount of code with most flexibility.
Remember that you can replace the button's background image with a state list drawable.
I'm having this question about setting pictures for Buttons in XML :
I made some .png pictures I want to set as pictures instead of the buttons that I get in default when i create my android apps.. Now I loaded in the files into the drawable folder.. And how do I write in XML to get the right thing?
Is setting the button visible to false and adding a picture as background for it an option?
Because that's all the ways I thought about. Or is there a better way to do this kind of thing?
what I understood is that you want to set the picture in background. Do it like this in your Button tag:
android:background="#drawable/yourpicturename"
Add the png to the drawable folder that is under the res folder in your project (if you are using eclipse). Then in your XML file simply use android:background="#drawable/filename". Make sure to omit the file extension
You can use any of:
drawableTop, drawableLeft, drawableRight, drawableBottom
For example,
<Button android:drawableRight="#drawable/some_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Some text" />
The image some_image.png will be positioned to the right of your text in this case.
Let's say i have a layout with style:
<LinearLAyout ... >
<TextView ... style=someStyle />
<ImageView ... style=someImageStyle ... />
</LinearLayout>
the style will be defined in an xml in my project.
How can i override that style with an external xml ? (i'm asking because i've noticed the View does not have applyStyle\setStyle or anything of that sort (best bet, because style need to be parsed, compared against android:attr for validation and then applied on each item of the view).
I do wonder how am i suppose to make downlaodable themes for my app.
After some experience i can share my thoughts about it here in my own question...
So first remark is, even in your own styles, use Dimentions and colors and attributes as much as you can. this way if you ever want to programatically apply a style to a view you can use getResources.getDimen... , getRessources().getColor(), getResrouces.getDrawable() etc...
In addition you can take the code from the aapt or open an existing apk and take the compiled xml from there and then use the same code reading the xml (it's C code mind you!!!) from android source. i would not do it from the simple reason it's an overkill to apply a simple style to a view.
The time it takes to write the method is too short. and if you must do it in xml, you can create an xml file with just your view and then inflate it, you can't replace the style in run time though. for that you have to define your own mechanism to replace colors, sizes, backgrounds etc... and supply the images as well, which is not so easy, reading those images from the local storage, if i'm not mistaken is less productive then readin them from assets or drawable directories.