-6

I am working on an offline dictionary app in android studio using SQLite database.

I want to make some text bold or color changed which I use in SQLite database.

How can I make text bold or can change the color of text stored in database.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • 3
    Possible duplicate of [How do you change text to bold in Android?](https://stackoverflow.com/questions/4792260/how-do-you-change-text-to-bold-in-android) – david Aug 05 '17 at 18:51
  • No, I want to make text bold in sqlite database. – M.B Android Aug 05 '17 at 18:53
  • Database won't show up styled text. But you can mark some text to be styled **in your app**. – Phantômaxx Aug 05 '17 at 19:07
  • How, Can you please explain. I am new to android. – M.B Android Aug 05 '17 at 19:13
  • Simply insert the markup where you want it to appear, surrounding the text you will store in the db. Then (in your app) you can use `HTML.fromHTML()` (very limited HTML tag support) to render it in a TextView. Or you can use a much heavier WebView. – Phantômaxx Aug 06 '17 at 14:46

3 Answers3

0

You can store the heading and paragraph/description in 2 different columns, then you can create 2 different TextViews one for the headings and set it like:

TextView heading = (TextView) findViewById(R.id.TextViewHeading);
heading.setTypeface(null, Typeface.BOLD);
heading.setText (heading);

And the description/paragraph TextView you can set like this:

TextView paragraph = (TextView) findViewById(R.id.TextViewParagraph);
paragraph.setText(SQLiteHelper.Paragraph);
HB.
  • 4,116
  • 4
  • 29
  • 53
0

You are welcome to store text in a database, using a data format that has a representation for bold. For example, HTML is text with "tags" for formatting, such as <b> for bold. Markdown — the "wikitext" language used for Stack Overflow questions and answers — uses double-asterisks for denoting boldface (e.g., **this would be in bold**). You are welcome to store HTML or Markdown in a database.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • @M.BAndroid: That depends entirely on what you do with the text after you retrieve it from the database. For example, if you save HTML in the database, and you load that HTML into a `WebView`, anything that you marked with `` tags will be show in boldface. – CommonsWare Aug 05 '17 at 19:07
  • I tried this but it shows tags as such. (Sorry I am new to android). – M.B Android Aug 05 '17 at 19:12
  • 1
    @M.BAndroid: Then consider asking a separate Stack Overflow question, where you provide a [mcve] demonstrating how you are loading HTML into the `WebView`, along with a link to a screenshot showing what you are getting as a result. – CommonsWare Aug 05 '17 at 19:14
  • Is there any other way, except sqlite database, where I can store my text easily in html format. – M.B Android Aug 06 '17 at 18:07
  • @M.BAndroid: You can save HTML in plain files. – CommonsWare Aug 06 '17 at 18:35
  • I did not know how? – M.B Android Aug 06 '17 at 18:37
  • @M.BAndroid: File I/O in Java and Android is covered in [the documentation](https://developer.android.com/training/basics/data-storage/files.html) and any decent book or course on Android app development. – CommonsWare Aug 06 '17 at 18:49
0

You could do this in sqlite but you don't need to, if you just want to change the weight on the front end of the app, but I'd have to see the code (codepen) or a screenshot at least.

kbrackson
  • 7
  • 3
  • Thank you, but I not want to change the weight of entire words, I just want to bold headings and remaining text should remain as such. – M.B Android Aug 06 '17 at 18:06