Search code examples
androiduser-interfacetabletsmartphone

Different UI for Tablet and Mobile


I am working with one Application for Tablet and Mobile mode.

I have confusion.

There is totally different UI and WEBAPI for one screen only.

Can I make these changes in the same app?

Or

I have to create a different application for Tablet mode?


Solution

  • Finally I solve my question by Using below code.

    Create bool.xml file under app > src > main > res > values > bool.xml

    Same for values, values-sw600dp, values-sw720dp

    bool.xml for values

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <bool name="isTablet">false</bool>
    </resources>
    

    bool.xml for values-sw600dp

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <bool name="isTablet">true</bool>
    </resources>
    

    bool.xml for values-sw720dp

    <?xml version="1.0" encoding="utf-8"?>
    <resources>
        <bool name="isTablet">true</bool>
    </resources>
    

    Now do just following things.

    // Global Variable
    boolean isTablet;
    
    //Get Value from values bool.xml file
     isTablet = getResources().getBoolean(R.bool.isTablet);
    
    //Now check condition
    if(isTablet){
          //Device is tablet
    }else{
          //Device is mobile
    }