2013-06-08 3 views
0

У меня есть несколько диалог в одной деятельности и каждая вещь отлично работать и диалог текст может бытьDialog Игнорировать цвет шрифта Тег HTML

полностью настроены из (string.xml) путем добавления HTML-теги.

код активность:

public class MyDay extends Activity { 
final Context context = this; 
private Button button; 
TextView tv1,tv2,tv3,tv4; 
String day; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.Layou 
     tParams.FLAG_FULLSCREEN); 
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 
Boolean customTitleSupported =  
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);  
setContentView(R.layout.day); 

if (customTitleSupported) {   
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title); 
} 

    initializeTextViews(); 
} 

private void initializeTextViews() { 
tv1=(TextView)findViewById(R.id.title_tv1); 
tv1.setTypeface(FontFactory.getBFantezy(getBaseContext())); 

tv2=(TextView)findViewById(R.id.day_tv1); 
tv2.setTypeface(FontFactory.getBFantezy(getBaseContext())); 

tv3=(TextView)findViewById(R.id.day_tv3); 
tv3.setTypeface(FontFactory.getBFantezy(getBaseContext())); 

    day=getIntent().getStringExtra("cheese"); 

if(day.equalsIgnoreCase("Day1")){ 
    tv1.setText("First Day");  
    tv2.setText(Html.fromHtml(getString(R.string.beginning))); 
    tv3.setText(Html.fromHtml(getString(R.string.day1))); 

    button = (Button) findViewById(R.id.city_button);   
    button.setOnClickListener(new OnClickListener() { 
    public void onClick(View arg0) { 
    // custom dialog 
    final Dialog dialog = new Dialog(context,R.style.cust_dialog); 
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);   
    dialog.setContentView(R.layout.custom_dialog); 
    // set the custom dialog components - text, image and button 
    TextView text = (TextView) dialog.findViewById(R.id.dialog_text); 
    text.setTypeface(FontFactory.getBFantezy(getBaseContext()));     
    text.setText(Html.fromHtml(getString(R.string.torusim_places_1))); 

    Button dialogButton = (Button) dialog.findViewById(R.id.dialog_Button);    
    dialogButton.setTypeface(FontFactory.getBFantezy(getBaseContext())); 
    dialogButton.setOnClickListener(new OnClickListener() { 
     public void onClick(View v) { 
      dialog.dismiss(); 
     } 
    }); 
      dialog.show(); 
     } 
    }); 
} 

else if(day.equalsIgnoreCase("Day2")){ 
    tv1.setText("Second Day"); 
    tv2.setText(Html.fromHtml(getString(R.string.beginning))); 
    tv3.setText(Html.fromHtml(getString(R.string.day2))); 

    button = (Button) findViewById(R.id.city_button);   
    button.setOnClickListener(new OnClickListener() {  
     public void onClick(View arg0) { 
     // custom dialog 
    final Dialog dialog = new Dialog(context,R.style.cust_dialog);     
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);   
    dialog.setContentView(R.layout.custom_dialog); 

    TextView text = (TextView) dialog.findViewById(R.id.dialog_text);    
    text.setTypeface(FontFactory.getBFantezy(getBaseContext()));    
    text.setText(Html.fromHtml(getString(R.string.torusim_places_2))); 

    Button dialogButton = (Button) dialog.findViewById(R.id.dialog_Button);   
    dialogButton.setTypeface(FontFactory.getBFantezy(getBaseContext())); 
     // if button is clicked, close the custom dialog 
     dialogButton.setOnClickListener(new OnClickListener() { 
      public void onClick(View v) { 
       dialog.dismiss(); 
       } 
      }); 
       dialog.show(); 
      } 
     }); 
     } 
else if(day.equalsIgnoreCase("Day3")){ 
    tv1.setText("Third Day"); 
    tv2.setText(Html.fromHtml(getString(R.string.beginning))); 
    tv3.setText(Html.fromHtml(getString(R.string.day3))); 

    button = (Button) findViewById(R.id.city_button);   
    button.setOnClickListener(new OnClickListener() {  
     public void onClick(View arg0) { 
    // custom dialog 
    final Dialog dialog = new Dialog(context,R.style.cust_dialog); 
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);   
      dialog.setContentView(R.layout.custom_dialog);     
    TextView text = (TextView) dialog.findViewById(R.id.dialog_text);    
    text.setTypeface(FontFactory.getBFantezy(getBaseContext()));    
    text.setText(Html.fromHtml(getString(R.string.torusim_places_3))); 

    Button dialogButton = (Button) dialog.findViewById(R.id.dialog_Button);    
    dialogButton.setTypeface(FontFactory.getBFantezy(getBaseContext())); 
     // if button is clicked, close the custom dialog 
    dialogButton.setOnClickListener(new OnClickListener() { 
      public void onClick(View v) { 
       dialog.dismiss(); 
      } 
     }); 
       dialog.show(); 
      } 
     }); 
    } 
} 
        // this continuing repeated till day 20 // 


public void handleClick(View v){ 

    Intent intent = new Intent(); 
    intent.setClass(this,DayGallery.class); 
    intent.putExtra("dayname",day); 
    startActivity(intent); 

       } 
     } 

String.xml:

<string name="torusim_places_1"> 
<![CDATA[  
<b><font color=#008000>* </b>This is <b><font color=#008080>First</b> line in 
    dialog <br/> 
<b><font color=#ff00ff>* </b>This is <b><font color=#FDD017>Second</b> line in 
    dialog <br/>   
<b><font color=#0000FF>* </b>This is <b><font color=#808000>Third</b> line in 
    dialog <br/> 
<b><font color=#59C9FA>* </b>This is <b><font color=#0000A0>Fourth</b> line in 
    dialog <br/> 
    ]]> 
</string> 

вывода изображения:

enter image description here

НО у меня есть 20 строк, поэтому я добавить диалоговые 20 раз, что является излишним, его работа хорошо, но я думаю, что есть лучший подход, чем то, что я сделал,

Так, согласно ответу моего предыдущего вопросаSet custom dialog once into activity

я применил ответил код, как показано ниже:

public class MyDay extends Activity { 
final Context context = this; 
private Button button; 
TextView tv1,tv2,tv3,tv4; 
String day; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
      WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 
Boolean customTitleSupported = requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 
    setContentView(R.layout.day); 

if (customTitleSupported) {    
    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.custom_title); 
} 

    initializeTextViews(); 
    } 

private void initializeTextViews() { 
    tv1=(TextView)findViewById(R.id.title_tv1); 
    tv1.setTypeface(FontFactory.getBFantezy(getBaseContext())); 

    tv2=(TextView)findViewById(R.id.day_tv1); 
    tv2.setTypeface(FontFactory.getBFantezy(getBaseContext())); 

    tv3=(TextView)findViewById(R.id.day_tv3); 
    tv3.setTypeface(FontFactory.getDroidNaskh(getBaseContext())); 

      day=getIntent().getStringExtra("cheese"); 

    if(day.equalsIgnoreCase("Day1")){ 
     tv1.setText("First Day");  
     tv2.setText(Html.fromHtml(getString(R.string.beginning))); 
     tv3.setText(Html.fromHtml(getString(R.string.day1))); 

     button = (Button) findViewById(R.id.city_button);   
     button.setOnClickListener(new OnClickListener() { 
     public void onClick(View arg0) {    
     dialogCreation(Html.fromHtml(getString(R.string.torusim_places_1)).toString()); 
     } 
    }); 
    } 

    else if(day.equalsIgnoreCase("Day2")){ 
     tv1.setText("Second Day"); 
     tv2.setText(Html.fromHtml(getString(R.string.beginning))); 
     tv3.setText(Html.fromHtml(getString(R.string.day2))); 

     button = (Button) findViewById(R.id.city_button);   
     button.setOnClickListener(new OnClickListener() {  
    public void onClick(View arg0) {        
     dialogCreation(Html.fromHtml(getString(R.string.torusim_places_2)).toString()); 
     } 
     }); 
    } 

    else if(day.equalsIgnoreCase("Day3")){ 
     tv1.setText("Third Day"); 
     tv2.setText(Html.fromHtml(getString(R.string.beginning))); 
     tv3.setText(Html.fromHtml(getString(R.string.day3))); 

     button = (Button) findViewById(R.id.city_button);   
     button.setOnClickListener(new OnClickListener() {  
    public void onClick(View arg0) {      
     dialogCreation(Html.fromHtml(getString(R.string.torusim_places_3)).toString()); 
     } 
    }); 
    } 
    } 
      // this continuing repeated till day 20 // 

public void handleClick(View v){ 
    //Create an intent to start the new activity. 
    Intent intent = new Intent(); 
    intent.setClass(this,DayGallery.class); 
    intent.putExtra("dayname",day); 
    startActivity(intent); 
      } 

public void dialogCreation(String arg0) { 
     // custom dialog 
    final Dialog dialog = new Dialog(context,R.style.cust_dialog); 
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);   
    dialog.setContentView(R.layout.custom_dialog); 
    // set the custom dialog components - text, image and button 
    TextView text = (TextView) dialog.findViewById(R.id.dialog_text); 
    text.setTypeface(FontFactory.getBFantezy(getBaseContext()));     
    text.setText(arg0); 

    Button dialogButton = (Button) dialog.findViewById(R.id.dialog_Button);    
    dialogButton.setTypeface(FontFactory.getBFantezy(getBaseContext())); 
    dialogButton.setOnClickListener(new OnClickListener() { 
    public void onClick(View v) { 
     dialog.dismiss(); 
     } 
    }); 
     dialog.show(); 
    } 
    } 

но у меня есть одна проблема с кодом ответил, который неведение цвета шрифта тега с тем же (ул ing.xml)

поэтому все слова взяли один цвет, который установлен в R.layout.custom_dialog.

String.xml:

<string name="torusim_places_1"> 
<![CDATA[  
<b><font color=#008000>* </b>This is <b><font color=#008080>First</b> line in 
    dialog <br/> 
<b><font color=#ff00ff>* </b>This is <b><font color=#FDD017>Second</b> line in 
    dialog <br/>   
<b><font color=#0000FF>* </b>This is <b><font color=#808000>Third</b> line in 
    dialog <br/> 
<b><font color=#59C9FA>* </b>This is <b><font color=#0000A0>Fourth</b> line in 
    dialog <br/> 
    ]]> 
</string> 

вывода изображения:

enter image description here

любая помощь будет оценена, спасибо

+0

цвет шрифта = '# 008000', вам пропущенный '' ? – Blackbelt

+0

@blackbelt my above String.xml отлично работает с моим кодом, но не работает, когда применяется ответный код, также я пробую ваш комментарий, он дал мне ошибку, спасибо –

ответ

0

я пытался таким образом: она дает меня (Samsung Galaxy Note N7000) оранжевый * и th е слово "первый" в зеленом

<string name="torusim_places_1"> 
    <![CDATA[<b><font color="#FF8000"> * </font></b>This is <b><font color="#008080">First</font></b>line in 
dialog<br />]]> 
    </string> 

INSTAND струны передать аргумент dialogCreate в целое:

public void dialogCreation(int arg0) { 
     // custom dialog 
    final Dialog dialog = new Dialog(context,R.style.cust_dialog); 
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);   
    dialog.setContentView(R.layout.custom_dialog); 
    // set the custom dialog components - text, image and button 
    TextView text = (TextView) dialog.findViewById(R.id.dialog_text); 
    text.setTypeface(FontFactory.getBFantezy(getBaseContext()));     
    text.setText(Html.fromHtml(getStrint(arg0)); 

    Button dialogButton = (Button) dialog.findViewById(R.id.dialog_Button);    
    dialogButton.setTypeface(FontFactory.getBFantezy(getBaseContext())); 
    dialogButton.setOnClickListener(new OnClickListener() { 
    public void onClick(View v) { 
     dialog.dismiss(); 
     } 
    }); 
     dialog.show(); 
    } 

и называют его dialogCreation(R.string.torusim_places_1);

+0

Я думаю, что это не вопрос того, как писать тег в string.xml но его в коде класса после изменения, это повлияет на применение тега цвет шрифта, потому что я проверил ваш код по-прежнему той же проблемы там, пожалуйста, проверьте обновленный пост, изображения добавлены также одна и та же строка.xml, используемый для обоих кодов, спасибо –

+0

, чтобы понять, где проблема, внутри dialogCreationg, изменить text.setText (arg0); с text.setText (Html.fromHtml (getString (R.string.torusim_places_1)) и проверьте, не изменилось ли это значение – Blackbelt

+0

, и изменил цвет шрифта также правильно, но я хочу, чтобы каждый torusim_places каждый день последовательно, как я могу сделать это, пожалуйста, спасибо –