Skip to content

Latest commit

 

History

History
102 lines (76 loc) · 2.44 KB

SETUP.md

File metadata and controls

102 lines (76 loc) · 2.44 KB

Bootstrap
Hello World
Access xml nodes from java

Bootstrap

Import .jar with library and natives from releases or build from sources.

Create folder structure on your project:

assets/
res/

assets: Folder for save all assets from your project.
res: Folder for save all resources a like texts, layouts, icons, themes, etc.

ProjectStructure

IMPORTANT: Ouput folders need follow that structure too.

Create a Hello World

For make a simple hello world:

public class Example extends Activity {
    public static void main(String[] args) {
        Application.initialize(new TexelProject("application.package",new Launch<>(Example.class)));
    }

    @Override
    public void onCreate() {
        super.onCreate();
        TextView view = new TextView(this);
        view.setText("Hello world");
        view.setGravity(Gravity.CENTER);
        view.setTextSize(32);
        view.setBackground(new ColorDrawable(Color.RED));
        setContentView(view);
    }
}

Preview

Create a UI with XML.

For create complex UIs you can use XMLs, first you need create your layout file res/layout/example.xml, that is a example of a simple Hello world layout:

<?xml version="1.0" encoding="UTF-8" ?>
<FrameLayout
    width="match_parent"
    height="match_parent"
    background="?colorSurface"
    orientation="horizontal">
  <Button
    width="wrap_content"
    height="wrap_content"
    layoutGravity="center"
    textSize="16dp"
    text="Hello World"/>
</FrameLayout>

For import that layout, you can use setContentView(layoutId) in your activity.

@Override
public void onCreate() {
    super.onCreate();
    setContentView("example");
}

Preview

Access XML Views from Java

For access and edit nodes created from xml layout, you can use method: findViewById('NODE_ID'), and set tag id in your xml code, example:

  <TextView
    id="NODE_ID"
    width="match_parent"
    height="match_parent"
    text="Hello world"/>
@Override
public void onCreate() {
    super.onCreate();
    setContentView("example");
    ((TextView)findViewById("NODE_ID")).setText("New text");
}

All views has a method findViewById('id') for find a child with specific id.