I have a card and want to add content to it. How should I add images and also Text to the card? Here is my xml code:
<?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"
tools:context="ml.vedantk.app.god.MainActivity">
<android.support.v7.widget.CardView
android:id="@+id/card1"
android:layout_width="364dp"
android:layout_height="389dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="64dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Here is the java file:
package ml.vedantk.app.god;
import android.support.annotation.ColorInt;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.CardView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CardView card1 = (CardView)findViewById(R.id.card1);
card1.setCardBackgroundColor(100);
}
}
The card1.setCardBackgroundColor(100);
also did not change the background color. So can anybody help me add an image?
setCardBackgroundColor(R.color.someColorName)