问题描述
在描述我更改日志的对话,我想有一些联系我们的Twitter和Facebook页面。因为我不想在文本裸网址,我使用 Html.fromHtml(..)
和标准的HTML链接样式(A HREF)。但是,我不能得到的链接,可以点击,不管我怎么做的对话框(通过要么是AlertDialog.Builder或自定义视图对话框)。我还设置 linksClickable = TRUE
在TextView的,但没有运气。如果有人可以帮助我,那简直太好了!
change_log_dialog.xml
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / linlay2
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:方向=垂直><的TextView
机器人:ID =@ + ID / dialog_text_view
机器人:layout_width =match_parent
机器人:layout_height =0dip
机器人:layout_margin =@扪/ view_padding
机器人:layout_weight =1
机器人:linksClickable =真
机器人:文字=@字符串/ gen_placeholder
机器人:textAppearance =机器人:ATTR / textAppearanceMedium>
< / TextView的><的LinearLayout
机器人:ID =@ + ID / VerticalLayout的
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:分=机器人:ATTR / dividerHorizontal
机器人:dividerPadding =0dip
机器人:方向=垂直
机器人:showDividers =开始> <按钮
机器人:ID =@ + ID / help_close
风格=机器人:ATTR / buttonBarButtonStyle
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:文字=@字符串/ help_close/>< / LinearLayout中>
调用该对话框当前方法:
对话对话框=新的对话框(本);
dialog.setTitle(R.string.changetitle);
视图V = getLayoutInflater()膨胀(R.layout.change_log_dialog,NULL);
((的TextView)v.findViewById(R.id.dialog_text_view))的setText(getRawAsset(R.raw.change));
dialog.setContentView(五);
返回对话框;
与getRawAsset(..):
公共跨区getRawAsset(INT ID){ 的InputStream Mstream工具= getResources()openRawResource(ID)。
InputStreamReader的MREAD =新的InputStreamReader(Mstream工具);
BufferedReader中的MReader =新的BufferedReader(MREAD);
StringBuilder的回归者=新的StringBuilder();
串线=;
尝试{
而((行= mReader.readLine())!= NULL){ returner.append(线); } 返回Html.fromHtml(returner.toString());
}赶上(IOException异常五){
e.printStackTrace();
}
返回null;}
也许你宁愿使用的的>而不是 Html.fromHtml(...)
。 Linkify
,伴随着的,应该能够在链接转换为更具人性化。
In a dialog describing my change log, I'd like to have some links to our twitter and facebook pages. Because I don't want to have the bare urls in the text, I'm using Html.fromHtml(..)
and standard html style links (a href). However, I can't get the links to be clickable, regardless of how I do the dialog (via either an AlertDialog.Builder or a Dialog with a custom view). I've also set linksClickable=true
in the textview, but no luck. If anyone could help me, that'd be great!
change_log_dialog.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linlay2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/dialog_text_view"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_margin="@dimen/view_padding"
android:layout_weight="1"
android:linksClickable="true"
android:text="@string/gen_placeholder"
android:textAppearance="?android:attr/textAppearanceMedium" >
</TextView>
<LinearLayout
android:id="@+id/verticallayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="?android:attr/dividerHorizontal"
android:dividerPadding="0dip"
android:orientation="vertical"
android:showDividers="beginning" >
<Button
android:id="@+id/help_close"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/help_close" />
</LinearLayout>
current method for calling the dialog:
Dialog dialog = new Dialog(this);
dialog.setTitle(R.string.changetitle);
View v = getLayoutInflater().inflate(R.layout.change_log_dialog, null);
((TextView) v.findViewById(R.id.dialog_text_view)).setText(getRawAsset(R.raw.change));
dialog.setContentView(v);
return dialog;
with getRawAsset(..):
public Spanned getRawAsset(int id) {
InputStream mStream = getResources().openRawResource(id);
InputStreamReader mRead = new InputStreamReader(mStream);
BufferedReader mReader = new BufferedReader(mRead);
StringBuilder returner = new StringBuilder();
String line = "";
try {
while ((line = mReader.readLine()) != null) {
returner.append(line);
}
return Html.fromHtml(returner.toString());
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
Perhaps you would rather use Linkify
instead of Html.fromHtml(...)
. Linkify
, along with Linkify.TransformFilter
, should be able to convert the links to something more user friendly.
这篇关于在对话框中点击链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!