2
내 활동에 일종의 "형식화 된"텍스트를 표시하려고합니다.TextView에서 클릭 가능한 단어
이 TextView 내의 일부 단어 (예 : 굵은 체로 표시)는 클릭 할 수 있어야합니다.
사용자가 토스트 메시지를 클릭하면 토스트 메시지가 표시됩니다.
Android에서 그렇게 할 가능성이 있습니까?
는내 활동에 일종의 "형식화 된"텍스트를 표시하려고합니다.TextView에서 클릭 가능한 단어
이 TextView 내의 일부 단어 (예 : 굵은 체로 표시)는 클릭 할 수 있어야합니다.
사용자가 토스트 메시지를 클릭하면 토스트 메시지가 표시됩니다.
Android에서 그렇게 할 가능성이 있습니까?
는내가 나를 위해 아마 더 나은 더 유연한 솔루션을 찾아 주셔서 감사합니다.
내 안드로이드 응용 프로그램에서 메서드를 호출하는 WebView, HTML 및 JavaScript-Functions를 사용할 수 있습니다.
public class MainScreen extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
WebView webview = new WebView(this);
setContentView(webview);
String data = "Test <u onClick=\"showAndroidToast('test')\">it</u>";
String js_data = "<script type=\"text/javascript\">function showAndroidToast(toast){Android.showToast(toast);}</script>";
webview.loadData(data + js_data, "text/html", "utf-8");
WebSettings webSettings = webview.getSettings();
webSettings.setJavaScriptEnabled(true);
webview.addJavascriptInterface(new JavaScriptInterface(this), "Android");
}
public class JavaScriptInterface
{
Context mContext;
/** Instantiate the interface and set the context */
JavaScriptInterface(Context c)
{
mContext = c;
}
/** Show a toast from the web page */
public void showToast(String toast)
{
Toast.makeText(mContext, toast, Toast.LENGTH_SHORT).show();
}
}
}
이것을 확인하십시오. answer – yjw