I'm trying to dynamically create a button, but nothing I've tried seems to be working. This is what I have so far:
Button test = new Button(this);
test.setText("test");
test.setBackgroundResource(R.color.blue);
test.setLayoutParams (new LinearLayout.LayoutParams(60,ViewGroup.LayoutParams.FILL_PARENT));
This is my xml file, it's a constraint layout, if that maybe conflicts with the dynamically created linear layout:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/profileLayout"
android:theme="@android:style/Theme.NoTitleBar"
tools:context="com.example.myfirstapp.MainActivity">
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="My Profile"
android:fontFamily="serif"
android:textColor="@color/green"
android:textAlignment="center"
android:textSize="30dp"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintVertical_bias="0.0" />
//Directory Icons
<ImageButton
android:id="@+id/profileDir"
android:layout_width="73dp"
android:layout_height="55dp"
android:backgroundTint="@color/orange"
android:scaleType="fitCenter"
android:src="@drawable/profile_icon"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintVertical_bias="1.0" />