kotlin - custom font to alertDialog











up vote
3
down vote

favorite












I must change default font of alertDialog.setMessage and alertDialog.setTitle but I can't use a custom layout, so I have to change it by code in Kotlin.
I tried using typeface, but he doesn't detect the font in res/font/product_sans_bold.ttf



I also used



content.text = Html.fromHtml(resources.getString(R.string.centripetaFormule))
content.typeface = ResourcesCompat.getFont(applicationContext, R.font.product_sans_bold)
alertDialog.setView(content)


and it works, but not as i want.



I have a string



<string name ="centripetaFormule>![CDATA[<h5>(...)</h5><p>(...)</p> 


where h5 is bold, so using variable content there will be no differences between h5 and "normal" text, except for the size.



So, I want to change font just for normal text, I can't use a custom layout, I have to use strings with CDATA.



How to do that?



Hope I explained it well










share|improve this question




























    up vote
    3
    down vote

    favorite












    I must change default font of alertDialog.setMessage and alertDialog.setTitle but I can't use a custom layout, so I have to change it by code in Kotlin.
    I tried using typeface, but he doesn't detect the font in res/font/product_sans_bold.ttf



    I also used



    content.text = Html.fromHtml(resources.getString(R.string.centripetaFormule))
    content.typeface = ResourcesCompat.getFont(applicationContext, R.font.product_sans_bold)
    alertDialog.setView(content)


    and it works, but not as i want.



    I have a string



    <string name ="centripetaFormule>![CDATA[<h5>(...)</h5><p>(...)</p> 


    where h5 is bold, so using variable content there will be no differences between h5 and "normal" text, except for the size.



    So, I want to change font just for normal text, I can't use a custom layout, I have to use strings with CDATA.



    How to do that?



    Hope I explained it well










    share|improve this question


























      up vote
      3
      down vote

      favorite









      up vote
      3
      down vote

      favorite











      I must change default font of alertDialog.setMessage and alertDialog.setTitle but I can't use a custom layout, so I have to change it by code in Kotlin.
      I tried using typeface, but he doesn't detect the font in res/font/product_sans_bold.ttf



      I also used



      content.text = Html.fromHtml(resources.getString(R.string.centripetaFormule))
      content.typeface = ResourcesCompat.getFont(applicationContext, R.font.product_sans_bold)
      alertDialog.setView(content)


      and it works, but not as i want.



      I have a string



      <string name ="centripetaFormule>![CDATA[<h5>(...)</h5><p>(...)</p> 


      where h5 is bold, so using variable content there will be no differences between h5 and "normal" text, except for the size.



      So, I want to change font just for normal text, I can't use a custom layout, I have to use strings with CDATA.



      How to do that?



      Hope I explained it well










      share|improve this question















      I must change default font of alertDialog.setMessage and alertDialog.setTitle but I can't use a custom layout, so I have to change it by code in Kotlin.
      I tried using typeface, but he doesn't detect the font in res/font/product_sans_bold.ttf



      I also used



      content.text = Html.fromHtml(resources.getString(R.string.centripetaFormule))
      content.typeface = ResourcesCompat.getFont(applicationContext, R.font.product_sans_bold)
      alertDialog.setView(content)


      and it works, but not as i want.



      I have a string



      <string name ="centripetaFormule>![CDATA[<h5>(...)</h5><p>(...)</p> 


      where h5 is bold, so using variable content there will be no differences between h5 and "normal" text, except for the size.



      So, I want to change font just for normal text, I can't use a custom layout, I have to use strings with CDATA.



      How to do that?



      Hope I explained it well







      android kotlin android-alertdialog






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 7 at 12:58









      forpas

      3,9361215




      3,9361215










      asked Nov 7 at 12:54









      Arfmann

      63212




      63212
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Android comes with a nice default font but in some cases you might want to use a different font.



          Fastest Way to use custom font android



          Put your font file in asset folder



          enter image description here



          Create Typeface Object



           Typeface customFont = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Bold.ttf")


          Set Typeface to TextView/EditText/Button etc…



          TextView textView = (TextView) findViewById(R.id.my_textview);
          textView.setTypeface(customFont);





          share|improve this answer





















          • Thanks for the answer, but the problem is that i have an Header and a "normal" text and they must have different fonts, so this method doesn't works well
            – Arfmann
            Nov 7 at 13:44











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53189861%2fkotlin-custom-font-to-alertdialog%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          Android comes with a nice default font but in some cases you might want to use a different font.



          Fastest Way to use custom font android



          Put your font file in asset folder



          enter image description here



          Create Typeface Object



           Typeface customFont = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Bold.ttf")


          Set Typeface to TextView/EditText/Button etc…



          TextView textView = (TextView) findViewById(R.id.my_textview);
          textView.setTypeface(customFont);





          share|improve this answer





















          • Thanks for the answer, but the problem is that i have an Header and a "normal" text and they must have different fonts, so this method doesn't works well
            – Arfmann
            Nov 7 at 13:44















          up vote
          0
          down vote













          Android comes with a nice default font but in some cases you might want to use a different font.



          Fastest Way to use custom font android



          Put your font file in asset folder



          enter image description here



          Create Typeface Object



           Typeface customFont = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Bold.ttf")


          Set Typeface to TextView/EditText/Button etc…



          TextView textView = (TextView) findViewById(R.id.my_textview);
          textView.setTypeface(customFont);





          share|improve this answer





















          • Thanks for the answer, but the problem is that i have an Header and a "normal" text and they must have different fonts, so this method doesn't works well
            – Arfmann
            Nov 7 at 13:44













          up vote
          0
          down vote










          up vote
          0
          down vote









          Android comes with a nice default font but in some cases you might want to use a different font.



          Fastest Way to use custom font android



          Put your font file in asset folder



          enter image description here



          Create Typeface Object



           Typeface customFont = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Bold.ttf")


          Set Typeface to TextView/EditText/Button etc…



          TextView textView = (TextView) findViewById(R.id.my_textview);
          textView.setTypeface(customFont);





          share|improve this answer












          Android comes with a nice default font but in some cases you might want to use a different font.



          Fastest Way to use custom font android



          Put your font file in asset folder



          enter image description here



          Create Typeface Object



           Typeface customFont = Typeface.createFromAsset(getAssets(), "fonts/Roboto-Bold.ttf")


          Set Typeface to TextView/EditText/Button etc…



          TextView textView = (TextView) findViewById(R.id.my_textview);
          textView.setTypeface(customFont);






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 7 at 13:20









          Jose Ribamar

          213




          213












          • Thanks for the answer, but the problem is that i have an Header and a "normal" text and they must have different fonts, so this method doesn't works well
            – Arfmann
            Nov 7 at 13:44


















          • Thanks for the answer, but the problem is that i have an Header and a "normal" text and they must have different fonts, so this method doesn't works well
            – Arfmann
            Nov 7 at 13:44
















          Thanks for the answer, but the problem is that i have an Header and a "normal" text and they must have different fonts, so this method doesn't works well
          – Arfmann
          Nov 7 at 13:44




          Thanks for the answer, but the problem is that i have an Header and a "normal" text and they must have different fonts, so this method doesn't works well
          – Arfmann
          Nov 7 at 13:44


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53189861%2fkotlin-custom-font-to-alertdialog%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Academy of Television Arts & Sciences

          L'Équipe

          1995 France bombings