我正在尝试更改AlertDialog消息的文本消息。成为一个可以接受的信息。 使用此代码,文本为蓝色,但不是clikable
我希望来自文字的手机,电子邮件和网站具有可嵌入性
final SpannableString All =
new SpannableString(textmess + "\n\nTel :\n " + phone + "\n\nEmail : \n " + email + "\n\nAddress: \n " + address + "\n\nWeb site : \n " + site );
Linkify.addLinks(All, Linkify.ALL );
AlertDialog.Builder builder = new AlertDialog.Builder( new
ContextThemeWrapper(context, R.style.AlertDialogCustom) );
builder.setTitle(title).setMessage(All);
builder.create();
//not working
//TextView textView = (TextView) findViewById(android.R.id.message);
builder.show();
GeoPoint1.close();
db1.close();
答案 0 :(得分:0)
为对话框创建自定义布局,并使用setMovementMethod
完成此操作
例如:
AlertDialog.Builder dialog = new AlertDialog.Builder(context);
LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
View view = inflater.inflate(R.layout.dialog_custom, null);
TextView dTitle = (TextView) view.findViewById(R.id.textDialogTitle);
TextView dMessage = (TextView) view.findViewById(R.id.textDialogMessage);
dMessage.setMovementMethod(LinkMovementMethod.getInstance());
dTitle.setText("Title");
dMessage.setText(ALL);
dialog.setView(view);
dialog.show();
答案 1 :(得分:0)
此示例可以帮助您:
res / layout / dialog.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#000000">
<TextView
android:id="@+id/tv_pc_forDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/tv_pc_dialogTitle"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="20dp"
android:ems="10"
android:layout_centerHorizontal="true"
android:text="THIS IS A CLICKABLE MESSAGE"
android:singleLine="true"
android:textColor="#FFFFFF" >
</TextView>
<TextView
android:id="@+id/tv_pc_dialogTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="5dp"
android:text="SEARCH"
android:textColor="#FFFFFF"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/bt_pc_goButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tv_pc_forDialog"
android:layout_centerHorizontal="true"
android:layout_marginTop="14dp"
android:text="GO"
android:textColor="#FFFFFF"
android:textSize="25sp" /> </RelativeLayout>
<强> RES /布局/ activity_main.xml中强>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="177dp"
android:text="Open Dialog" />
</RelativeLayout>
MainActivity.java:
package com.bhavit.stackoverflow;
import android.os.Bundle;
import android.app.Activity;
import android.app.Dialog;
import android.graphics.Typeface;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button openDialog = (Button) findViewById(R.id.button1);
openDialog.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Dialog dialog = new Dialog(MainActivity.this); // here write the name of your activity in place of "YourActivity"
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog);
TextView tv = (TextView)dialog.findViewById(R.id.tv_pc_dialogTitle);
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/GOTHIC.TTF"); // here GOTHIC.TTF is the font-file I have pasted in the asset/fonts folder in my project
tv.setTypeface(tf); // Set the typeface like this
Button bt = (Button) dialog.findViewById(R.id.bt_pc_goButton);
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Write here, what do you want to do on button click
}
});
TextView tview = (TextView) dialog.findViewById(R.id.tv_pc_forDialog);
tview.setOnClickListener(new View.OnClickListener() { // set onClickListener to the textview
@Override
public void onClick(View v) {
// Write here, what do you want to do on Message click
Toast.makeText(getApplicationContext(), "You clicked on message", Toast.LENGTH_LONG).show();
}
});
dialog.show();
}
});
}
}
我在这里做的是我创建了一个自定义对话框,并在TextView上设置一个onClickListener,显示为一条消息。像这样,你可以实现你的目标。