Z!dd0 Posted July 9, 2010 Share Posted July 9, 2010 (edited) Salut! J'ai un LinerLayout avec une TextView et une ImageView J'aimerais faire la meme chose qu'avec un bouton: wquand on cliques, le background change. J'arrive a faire ca quand je focus sur l'objet (avec la trackball), mais pas quand je clique :( J'ai essaye plein de choses differentes, mais rien n'a fonctionne... Des idees? merci d'avance Mon Linear Layout: android:orientation="horizontal" android:id="@+id/widgetProvider" android:layout_width="fill_parent" android:layout_height="wrap_content" android:focusableInTouchMode="true" android:clickable="true" android:layout_margin="1dip" android:background="@drawable/textview"> android:id="@+id/imgProvider" android:layout_width="60dip" android:layout_height="fill_parent" android:layout_marginRight="5dip" android:src="@drawable/icon" /> android:layout_width="fill_parent" android:layout_height="fill_parent" android:maxHeight="10dip" android:text="@string/provider" android:gravity="center_vertical"> Mon background qui change (textview.xml) Edited July 13, 2010 by Z!dd0 Quote Link to comment Share on other sites More sharing options...
Infernus Posted July 9, 2010 Share Posted July 9, 2010 Fait le avec un bouton plutôt qu'un textview. Ensuite dans ton code tu rajoutes. Imaginons que ton bouton se nomme : bouton bouton.setBackgroundResource(R.***.textview); Remarque ca doit aussi fonctionner avec une textview ;) Quote Link to comment Share on other sites More sharing options...
Z!dd0 Posted July 12, 2010 Author Share Posted July 12, 2010 Dans mon fichier layout, je peux pas mettre bouton a la place de "textview"! Quote Link to comment Share on other sites More sharing options...
Nivek Posted July 12, 2010 Share Posted July 12, 2010 Ptetre parce qu'il faut l'écrire "button" ? Quote Link to comment Share on other sites More sharing options...
Z!dd0 Posted July 12, 2010 Author Share Posted July 12, 2010 Comme ca tu veux dire??? android:orientation="horizontal" android:id="@+id/widgetProvider" android:layout_width="fill_parent" android:layout_height="wrap_content" android:focusableInTouchMode="true" android:clickable="true" android:layout_margin="1dip" android:background="@drawable/textview"> android:id="@+id/imgProvider" android:layout_width="60dip" android:layout_height="fill_parent" android:layout_marginRight="5dip" android:src="@drawable/icon" /> android:layout_width="fill_parent" android:layout_height="fill_parent" android:maxHeight="10dip" android:text="@string/provider" android:gravity="center_vertical"> Quote Link to comment Share on other sites More sharing options...
Fluckysan Posted July 12, 2010 Share Posted July 12, 2010 (edited) Oui comme ça en séparant bien : android:id="@+id/btnProvider" android:layout_width="fill_parent" android:layout_height="fill_parent" android:maxHeight="10dip" android:text="@string/provider" android:gravity="center_vertical"> Ensuite il faut que tu codes ton click avec un OnClickListener Tu peux le faire avec un TextView aussi puisque TextView dérive de View qui a OnClickListener (Button dérive de TextView aussi :p) Edited July 12, 2010 by Fluckysan Quote Link to comment Share on other sites More sharing options...
Infernus Posted July 12, 2010 Share Posted July 12, 2010 Je confirme ce que dit FluckySan, d'ailleurs c'est la même idée, entre ImageButton et ImageView :) Quote Link to comment Share on other sites More sharing options...
akex Posted July 12, 2010 Share Posted July 12, 2010 Tout dépend l'utilisation en effet. Z!dd0 : il faudrait que tu nous dises ce que tu souhaites faire exactement. TextView peut s'avérer être suffisant pour tes besoins. Quote Link to comment Share on other sites More sharing options...
Z!dd0 Posted July 12, 2010 Author Share Posted July 12, 2010 Merci a tous de vos reponses :) En fait, on peut voir dans le layout que mon element principal se compose d'une image (a gauche) et d'une zone de texte (a droite). Basiquement, c'est ca: ********************************* | | | | Image | Texte Texte | | | | ********************************* Ce que je veux, c'est que quand je clique sur le tout (n'importe ou), cela fonctionne comme un bouton et ca fasse une action. J'arrive a faire ca, sauf que cet element ne se highlighte pas. Il ne change pas de couleur quand on appuie dessus alors que j'ai bien mentionne dans le layout le "state_pressed" J'espere que vous comprenez un peu mieux mon probleme ;) Quote Link to comment Share on other sites More sharing options...
Nivek Posted July 12, 2010 Share Posted July 12, 2010 Bah il suffit d'utiliser un Bouton et de lui affecter une image avec l'attribut drawableLeft : android:drawableLeft="@android:drawable/ic_menu_add" android:layout_width="fill_parent" android:layout_gravity="center_horizontal" android:id="@+id/BtnCreateAlbum" /> non ? Quote Link to comment Share on other sites More sharing options...
Z!dd0 Posted July 12, 2010 Author Share Posted July 12, 2010 Oui, je pourrais utiliser ca, mais les images que j'affiche sont dynamiques et vienennt du net, donc je prefererai utiliser une imageview... Je ne vois vraiment pas pourquoi le "state_pressed" ne donne rien :( Quote Link to comment Share on other sites More sharing options...
Nivek Posted July 12, 2010 Share Posted July 12, 2010 (edited) Tu peux le faire au runtime : http://developer.android.com/reference/android/widget/TextView.html#setCompoundDrawablesWithIntrinsicBounds(android.graphics.drawable.Drawable,%20android.graphics.drawable.Drawable,%20android.graphics.drawable.Drawable,%20android.graphics.drawable.Drawable) Edited July 12, 2010 by Nivek Quote Link to comment Share on other sites More sharing options...
Z!dd0 Posted July 12, 2010 Author Share Posted July 12, 2010 Ouais je vais essayer de faire ca, merci. Mais sinon, il est donc impossible de highlighter un textview? Quote Link to comment Share on other sites More sharing options...
akex Posted July 12, 2010 Share Posted July 12, 2010 T'as regardé par ici ? http://developer.android.com/guide/topics/resources/color-list-resource.html Sur quel view as-tu activé le onClickListener ? Il faut que celle où est paramétrée la couleur (state_pressed) et celle où tu cliques soient la même. Quote Link to comment Share on other sites More sharing options...
Z!dd0 Posted July 13, 2010 Author Share Posted July 13, 2010 Oui, j'avais jete un oeil la-dessus. J'ai resolu le probleme: en fait, j'avais un onTouchListener au lieu d'un onClicklistener, et le highlight n'etait pas possible. Avec le onClickListener, tout se passe bien! Merci beaucoup! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.