Skip to main content

How do I fix Html.fromHtml link focus visibility problems (in ICS and Honeycomb)?



To get a TextView to display (and act friendly with) Html strings my code looks something like:







// itemHtml is a String of HTML defined above



TextView itemContent = (TextView) findViewById(R.id.itemContent);

itemContent.setText(Html.fromHtml(itemHtml));

itemContent.setMovementMethod(LinkMovementMethod.getInstance());







If the Html string has a link, TextView results in links that are clickable and focusable. When the user focuses on a specific link (e.g. by using the d-pad), the link text changes in some significant way to show that focus was obtained.





The problem is that when I test this same pattern using devices with a d-pad using Honeycomb (e.g. a Google TV) or Ice Cream Sandwich flavors of Android, the link in the text shows no noticeable indication that the link has focus.





I know it is getting focus, because when you then hit enter it does the specified action. You can even move around between various links in the text; you're just left guessing which link you're currently at, which results in a very bad user experience.





Is there something I'm doing wrong? Is there some way to fix this or work around this?



Source: Tips4all

Comments

  1. Edit: After going a bit nuts, I finally thought I found a solution. However, this solution only works for Honeycomb. ICS is still not solved!

    As of API 11, Android has a new setting on TextViews for defining whether the text is selectable.

    You can set it using setTextIsSelectable(true) on a TextView, or define it in the XML layout android:textIsSelectable="true"

    It's probably best to define it in XML, so that keeping the app backwards-compatible is trivial. Just make sure you're targeting version >= 11, or you'll probably get an error.

    ReplyDelete
  2. The way HTML.fromHTML operates is by creating "spans" with varying effects throughout the various characters of the string. One workaround for this would be to use ClickableSpan coupled with another of the CharacterStyles to colorize the text as clickable. The previous span will allow you to register a callback, and this callback could be to broadcast an intent to view a url (which would open a browser).

    ReplyDelete
  3. The text colour state lists for Honeycomb+ might not set the focused state to a different colour, or you override the colour to be constant.

    Check the colors + styles in your_android_sdk_directory/android-14/data/res/

    Setting the text to android:autoLink="web" might also help?

    ReplyDelete
  4. The best way to do that is to add CSS styling to your html. I know Android supports :hover selector. So you might right something like this:

    String myLink = "<a href=\"http:\/\/google.com\">your link</a>"
    Html.fromHtml(myLink);


    and find a way to include CSS data to it: (I'm not sure how but I think it's possible)

    a :hover {
    color: red;
    }


    UPDATE:

    I think the answer of your question is there.

    ReplyDelete

Post a Comment

Popular posts from this blog

[韓日関係] 首相含む大幅な内閣改造の可能性…早ければ来月10日ごろ=韓国

div not scrolling properly with slimScroll plugin

I am using the slimScroll plugin for jQuery by Piotr Rochala Which is a great plugin for nice scrollbars on most browsers but I am stuck because I am using it for a chat box and whenever the user appends new text to the boxit does scroll using the .scrollTop() method however the plugin's scrollbar doesnt scroll with it and when the user wants to look though the chat history it will start scrolling from near the top. I have made a quick demo of my situation http://jsfiddle.net/DY9CT/2/ Does anyone know how to solve this problem?

Why does this javascript based printing cause Safari to refresh the page?

The page I am working on has a javascript function executed to print parts of the page. For some reason, printing in Safari, causes the window to somehow update. I say somehow, because it does not really refresh as in reload the page, but rather it starts the "rendering" of the page from start, i.e. scroll to top, flash animations start from 0, and so forth. The effect is reproduced by this fiddle: http://jsfiddle.net/fYmnB/ Clicking the print button and finishing or cancelling a print in Safari causes the screen to "go white" for a sec, which in my real website manifests itself as something "like" a reload. While running print button with, let's say, Firefox, just opens and closes the print dialogue without affecting the fiddle page in any way. Is there something with my way of calling the browsers print method that causes this, or how can it be explained - and preferably, avoided? P.S.: On my real site the same occurs with Chrome. In the ex