How do I use HTML or CSS in Android Studio?

Asked

Viewed 4,924 times

1

I would like to know how to structure my app with HTML, and style it with CSS as well. I want to put a fieldset to form a table. I looked for tutorials on the Internet but did not understand well how to use.

I want lvDolar, from the XML below, to be bypassed by a fieldset:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context="com.example.teste.application.VerDolar"
    android:background="@color/white">

    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        **android:id="@+id/lvDolar"**
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="0dp" />
</RelativeLayout>

This is my java class:

package teste;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.example.rainah.application.R;

import java.util.List;


public class VerDolar extends ActionBarActivity {

    private ListView lvDolar;
    private List<Dolar> dolar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ver_dolar);
        setTitle("Dolar");

        lvDolar = (ListView) findViewById(R.id.lvDolar);
    }

    @Override
    protected void onResume() {
        super.onResume();

        DbHelper db = new DbHelper(this);
        List<Dolar> listDolar = db.selectDolar();

        ArrayAdapter<Dolar> list = new ArrayAdapter<Dolar>(this, android.R.layout.simple_list_item_1, listDolar);

        lvDolar.setAdapter(list);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_ver_dolar, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        //int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        switch(item.getItemId()) {
            case R.id.action_search:
                break;
            case R.id.action_new:
                Intent intent = new Intent(this, AddDolar.class);
                startActivity(intent);
                break;
            default:
                return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

I appreciate if anyone can help me, because I believe it is a relatively simple question, but I’m breaking my head to understand how it works in android studio. Thanks in advance.

  • Android Studio is focused on Android app, I don’t know if you can do this with this IDE. What people do, is develop a responsive web page, and create an app that accesses that page.

2 answers

2

To use CSS in an Android application, you must have your entire application within a Webview, that is, you cannot make the XML defined components of an Activity take the style of a CSS.

The style applied to an Activity (or elements of it) must be programmed in the Activity XML itself or in a separate xml (usually Styles.xml).

To actually use CSS, rewrite your application in an HTML "application" and on Android use a Webview to display your application’s Htmls. (see 3rd link of references). To create HTML "applications", you can use Phongegap or Ionic, which has good community support and to program require knowledge of HTML, CSS and Javascript (Angular).

Finishing: To solve your problem in fact, that is to put a fieldset around the field, there are some alternatives: - adding a Textview behind the component, without text, slightly larger than the component to simulate the border; - add a "Shape" around the component; - add a Bitmap behind the component.

References:

https://stackoverflow.com/questions/3496269/how-to-put-a-border-around-an-android-textview

http://android-pro.blogspot.com.br/2010/08/using-themes-and-styles-in-android.html

http://www.c-sharpcorner.com/UploadFile/bd6c67/use-html-and-css-file-in-android-apps/

https://developer.android.com/guide/topics/ui/themes.html

https://developer.android.com/guide/topics/resources/drawable-resource.html

http://www.devmedia.com.br/android-layouts-aprendendo-tecnicas-de-layout-no-android/30790

-1

The android studio is focused on the development of native applications, to use HTML and CSS suggest the use of CORDOVA, for the development of hybrid applications, a suggestion also instead of developing the responsive layout, which gives a certain work, try to use a market framework suggest IONIC

Link:

https://cordova.apache.org/

https://ionicframework.com/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.