Gallery view remove focus - Android - android

I want to remove focus in gallery for a selected item. I am getting an output like this, Here is an image :
Here first item selected. So it is looking darker than 2nd image. I want to display an image as it is not focused or selected.
Please anyone help. I'll really appreciate that.
Thanks

Create a statelist drawable (see http://developer.android.com/reference/android/graphics/drawable/StateListDrawable.html) and customize the "selected" state to whatever you want there, in your case transparent . Then you provide this drawable as the background for the item.
EDIT:
Also look in to gallery
android:unselectedAlpha

try to apply below two property in your xml to your gallery.
android:focusableInTouchMode="false"
android:focusable="false"

you can use something like
View.clearFocus()
LinearLayout myLayout = (LinearLayout) activity.findViewById(R.id.my_layout);
myLayout.requestFocus();

Related

Creating icons in application activity and making them transparent

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.

Best way to program buttons/images

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.

Getting ListView drawables and applying it manually

i am trying to apply the style that a list item has, when it is selected, to a View (In my case a TextView)
Example
here it would be the orange-painted style. I found that this look is defined by a Drawable Object. So i tried, so get the drawable and applied it to my view
TextView tv = new TextView(this);
tv.setText("Hello, Android");
tv.setBackgroundDrawable(new ListView(this).getSelector());
setContentView(tv);
but it doesn't work.
Does anybody have an idea how to do that?
Ok I figured out how to do that. I found out hat ListView uses the ColorStateList list_selector_background which is defined in android.R.drawable. Using ResourceBrowser I got to know that the fourth color is the selected drawable so i added the following to my code
StateListDrawable listDrawables= (StateListDrawable)getResources().getDrawable(android.R.drawable.list_selector_background);
listDrawables.selectDrawable(3);
Drawable highlightDrawable = listDrawables.getCurrent();
Now I can set my Background using higlightDrawable. I don't know if it is possible to access the drawable in xml I did not try it yet. Thanks for help!
It would be a pain to do it by code.
You need to implement a selector and let android know which resource needs to be used when the view is pressed, enabled or focused.
Here is sample example on how to achieve the same.

Changing background color for items of Spinner

I am working on Android application.I am using Spinner control and added items to it.
Is there a way to change the background color of items in spinner.
can any one help me in sorting out this issue.
Thanks in Advance,
If you completely want to customize your background spinner, you should use 9patch background.
Here is a tutorial that explain how to do that :
http://www.gersic.com/blog.php?id=57
Otherwise, the solution given by user432209 is the simplest.
However, if you want to do that in xml layout :
<Spinner android:id="#+id/spinner"
...
android:background="#YOUR_HEXA_COLOR"/>
You can use
yourView.setBackgroundColor(int color)
You can also use android:popupBackground="YOUR COLOR" which will define the items background not the whole spinner's background.

Android how to make View highlight when clicked?

I have a linear layout in which each row is inflated programatically and I want the rows to behave like the ListView when clicked on. That is, I want the row to highlight in the exact same way/colour that the default ListView does. How would I go about doing this?
Ok I have finally figured out how to do this...basically it is done using a selector like the color selector linked by style except instead of 'color' use a drawable for the states and you can refer to the default list drawable that is used in ListView by this:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="#android:drawable/list_selector_background" />
</selector>
and using this xml as the background for my View.
All the public default drawables can be found here: http://developer.android.com/reference/android/R.drawable.html
I was able to do the same with a text view that I wanted to behave like a list item by using:
<Textview
....
android:background="#android:drawable/list_selector_background"
/>
This might be a good place to start looking.
Although, i would advise you to use the ListView itself, rather than implementing it again.
if you still have a problem with that then please remember that some of UI elements are not clickable (RelativeLayout), so you have to add one more line:
<RelativeLayout
....
android:clickable="true"
...
To your listview set property
android:listSelector="#color/test"
and this test color set any transparent color you like. you can create any transparent color by using hex transparent color

Categories

Resources