2016-01-26 92 views
1

非常簡單的問題,我無法找到答案:如果我有一個文本的WebView,是否有可能使它不會被包裝,並且只有一行?Android:將WebView文本限制爲一行?

例如:

String string = "this is a long text that will be wrapped";

通常將被顯示:

This is a long text that will be wrapped

我需要它是在web視圖單行。有什麼想法嗎?

回答

1

你可以這樣做如下:

String start = "<html><head><meta http-equiv='Content-Type' content='text/html' charset='UTF-8' /><style> body { 
white-space: nowrap;}</style></head><body>"; 

String end = "</body></html>"; 

webView.loadDataWithBaseURL(null, start + yourContent + end, null, "text/html; charset=UTF-8", null); 

空白:NOWRAP;當您在樣式中應用您的測試單行