2013-06-08 2 views
0

J'ai plusieurs dialogue dans une activité et tout fonctionne à la perfection et le dialogue texte peut êtredialogue Ignorer la police Couleur Html Tag

entièrement personnalisé de (string.xml) par l'ajout de balises html.

code d'activité:

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> 

image de sortie:

enter image description here

mais j'ai 20 ligne donc j'ajoute dialogue 20 fois ce qui est redondant, son beau travail, mais je pense qu'il ya une meilleure approche que ce que je l'ai fait,

Alors que par réponse de ma précédente questionSet custom dialog once into activity

i appliqué le code ci-dessous comme une réponse:

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(); 
    } 
    } 

mais j'avoir un problème avec le code réponse qui est ignorance de la balise de couleur de police avec le même (str ing.xml)

donc tous les mots ont pris une couleur qui est définie dans 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> 

image de sortie:

enter image description here

toute aide sera appréciée, merci

+0

font color = '# 008000', vous manqué '' ? – Blackbelt

+0

@blackbelt ci-dessus String.xml fonctionne parfaitement avec mon code mais ne fonctionne pas lorsqu'il est appliqué le code répondu, aussi j'essaye votre commentaire, il m'a donné l'erreur, merci –

Répondre

0

J'essayé de cette façon: il donne à moi (Samsung Galaxy Note N7000) une orange * et e "d'abord" mot en vert

<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 d'une chaîne passe l'argument de dialogCreate int:

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(); 
    } 

et l'appeler comme dialogCreation(R.string.torusim_places_1);

+0

je pense que ce n'est pas la question de savoir comment écrire tag dans string.xml mais son dans le code de la classe après changé, il affecte appliquer la balise de couleur de police, parce que j'ai vérifié votre code toujours le même problème là, s'il vous plaît vérifier mise à jour post, images ajoutées également la même chaîne.xml utilisé pour les deux codes, merci –

+0

afin de comprendre où le problème est, dans dialogCreationg, changez text.setText (arg0); avec text.setText (Html.fromHtml (getString (R.string.torusim_places_1)), et vérifiez si cela fait une différence – Blackbelt

+0

j'ai changé et obtenir la couleur de la police a changé aussi correctement mais je veux assigner chaque torusim_places à chaque jour de manière séquentielle, comment puis-je le faire s'il vous plaît, merci –

Questions connexes