Jak wyświetlić symbol podwójnego cudzysłowu (") w TextView?


97

Próbuję wyświetlić niektóre słowa w podwójnych cudzysłowach, w widoku tekstu w pliku xml. Ale to nie działa. Proszę pomóż mi.

    <TextView 
    style="@style/TextStyle" 
    android:text="message "quote string 1" and "quote string 2" end message" 
    android:id="@+id/lblAboutPara3" 
    android:autoLink="web"/>    

Każdy zna rozwiązanie tego problemu .............

Odpowiedzi:


192

W programie strings.xmlmożesz po prostu zmienić znaczenie znaków specjalnych (np. Podwójnych cudzysłowów) za pomocą odwrotnego ukośnika:

"message \"quote string 1\" and \"quote string 2\" end message"

Ale w widokach xml (np. layout.xml) Musisz używać encji znakowych HTML (takich jak &quot;):

"message &quot;quote string 1&quot; and &quot;quote string 2&quot; end message"

Aby uzyskać więcej, odwiedź http://developer.android.com/guide/topics/resources/string-resource.html


6
Działa w strings.xml <string name = "double_quote"> \ "</string>, ale nie w layout.xml
Tyler Davis

Ta odpowiedź jest niepoprawna, ponieważ OP konkretnie pyta o „podwójne cudzysłowy, w widoku tekstu w pliku xml”, a nie w strings.xml.
Patrick

70

Użyj &quot;symbolu, aby rozwiązać ten problem z twardym kodem :)

android:text="message &quot;quote string 1&quot;" 

1
To musi być poprawne i jeśli chcesz " symbol w pliku układu bez użycia string.xml .
Jaydipsinh Zala

1
Fakt, że nie możesz tego użyć, strings.xmljest dużym problemem.
Mike Baxter

14

używać escape characters. Aby wyświetlić cudzysłowy, użyj\"

Twój kod będzie

android:text="message \"quote string 1\" and "quote string 2\" end message" 

10

Proszę spróbować

<TextView 
style="@style/TextStyle" 
android:text='message \"quote string 1\" and \"quote string 2\" end message' 
android:id="@+id/lblAboutPara3" 
android:autoLink="web"/> 



6
<TextView 
style="@style/TextStyle" 
android:text='message "quote string 1" and "quote string 2" end message' 
android:id="@+id/lblAboutPara3" 
android:autoLink="web"/> 


1

Użyj apostrofów do zawijania wiadomości i możesz użyć tylu cudzysłowów, ile chcesz w ciągu.

android:text='message "quote string 1" and "quote string 2" end message'
Korzystając z naszej strony potwierdzasz, że przeczytałeś(-aś) i rozumiesz nasze zasady używania plików cookie i zasady ochrony prywatności.
Licensed under cc by-sa 3.0 with attribution required.