Search code examples
androidtextviewgravitytext-alignmentdirection

What is TextView Gravity by default?


It seems TextView text direction (or Gravity) automatically changes in Android when it gets text from RTL resources such as Arabic text or LTR resources like English. What is the default TextView direction (or Gravity) and how to get that? Actually I'm trying to find out what kind of text language (RTL or LTR) is entered? And what if it is hybrid text with both RTL and LTR?


Solution

  • What is the default TextView direction (or Gravity)

    In the TextView source code it is initialized as:

    private int mGravity = Gravity.TOP | Gravity.START;
    

    It seems Gravity.TOP and Gravity.START. The Gravity START is independent for LTR or RTL.

    and how to get that

    So getting it (you only know it Gravity.START) is non-sense for your purpose -- to find out what kind of text language (RTL or LTR) is entered.

    For other approach you can estimate whether text itself is RTL or LTR; discussed here: Identifyng RTL language in Android for example.