2010-12-27 5 views
5

나는 두 가지 질문이 있습니다Android : 형식 경고 대화 상자에서

1) 아는 사람, 스타일을 적용하거나 대화 상자에 경고를 표시하는 방법. 현재 Builder builder = new AlertDialog.Builder(this);을 사용하고 setMessage() 메서드를 사용하여 내용을 설정하십시오.

2) 또한 linkify로 만든 링크의 색상을 변경하는 방법을 알고 싶습니다. 기본 파란색을 원하지 않습니다.

답변

12

Q1. 당신은 팽창 또는 사용자 정의 스타일을 만들고 레이아웃을 부풀려 방법에 AlertDialog

을 Heres에 적용

LayoutInflater li = LayoutInflater.from(ctx); 
View view = li.inflate(R.layout.formatted_dialog, null); 

AlertDialog.Builder builder = new AlertDialog.Builder(ctx); 
builder.setTitle("Formatted"); 
builder.setView(view); 

모든 서식 및 사용자가 지정한 레이아웃에 필요한 스타일을 정의에 AlertDialog

에 적용해야합니다.

당신은 레이아웃에 정의 된 특정 텍스트 뷰에 액세스 할 수는보기 즉

LayoutInflater li = LayoutInflater.from(ctx); 
View view = li.inflate(R.layout.formatted_dialog, null); 
TextView label=(TextView)view.findViewById(R.id.i_am_from_formatted_layout_lable); 

Q2 비정상적으로 사용. android:textColorLink="#FF00FF"은 링크 색상을 지정하는 데 사용할 수 있습니다.

편집 : 당신의에서 onCreate에서

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <TextView 
    android:id="@+id/text" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="http://www.google.com" 
    android:autoLink="web" 
    android:textColorLink="#FF00FF" 
    /> 

</LinearLayout> 

() 또는 경우 또는

LayoutInflater li = LayoutInflater.from(this); 
View view = li.inflate(R.layout.link, null); 

AlertDialog.Builder builder = new AlertDialog.Builder(this); 
builder.setTitle("Formatted"); 
builder.setView(view).create().show(); 
TextView text=(TextView) findViewById(R.id.text); 
에 AlertDialog를 호출 할 때마다 :

샘플 레이아웃 고해상도/레이아웃/link.xml로 저장

다른 방법으로 호출하는 경우 this을 컨텍스트 개체로 바꿉니다.

+0

나는 몇 가지 의문이있다. formatted_dialog 레이아웃은 어떻게됩니까? 그렇다면 내 콘텐츠를 어떻게 추가해야합니까? 그리고'android : textColorLink'를 어디에 지정해야합니까? – Vivek

+0

견본이 추가되었습니다. 이것이 당신에게 명확한 생각을 줄 수 있기를 바랍니다. – Shardul

+0

AlertDialog에서 서체 사용법을 알려주시겠습니까 –

3

당신은 기본에 AlertDialog에서 텍스트 뷰를 추출하여 서체와 글자 색을 변경하려면 다음 코드를 사용할 수 있습니다

TextView txtAlertMsg = (TextView)alert.findViewById(android.R.id.message); 
txtAlertMsg.setGravity(Gravity.CENTER); 
+1

안녕하세요. 아난드 님, 내가 한 말처럼 해봤지만 잘못하고있는 부분을 파악할 수는 없습니다. Gravity set에서 NullPointerException이 발생했습니다. 내 코드는 다음과 같습니다. AlertDialog.Builder builder = new AlertDialog.Builder (context); builder.setIcon (0); builder.setTitle ("내 제목"); builder.setMessage (msg); builder.setNeutralButton ("Ok", null); AlertDialog alertDialog = builder.create(); alertDialog.show(); ((TextView) alertDialog.findViewById (android.R.id.title)). setGravity (Gravity.CENTER); ((TextView) alertDialog.findViewById (android.R.id.message)). setGravity (Gravity.CENTER); – Kalpesh