Hello friends,
If you want create gradient but not using xml then follow below instructions and code.
MainActivity.java
private LinearLayout ll_mainLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ll_mainLayout=(LinearLayout)findViewById(R.id. ll_main);
ll_mainLayout.setBackgroundResource(R.drawable. getgradiantInit);
}
public GradientDrawable getgradiantInit() {
int[] colors = {Color.parseColor("#F28542"), Color.parseColor("#F74368")};
GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors);
gd.setCornerRadius(20f);
return gd;
}
private GradientDrawable getgradiantFirst() {//3AA2E2
int[] colors1 = {Color.parseColor("#46AF62"), Color.parseColor("#3AA2E2")};//3AA2E2
GradientDrawable gd1 = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors1);
gd1.setCornerRadius(20f);
return gd1;
}
private GradientDrawable getgradiantSecond() {
int[] colors1 = {Color.parseColor("#EFB410"), Color.parseColor("#D14654")};
GradientDrawable gd1 = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors1);
gd1.setCornerRadius(20f);
return gd1;
}
private GradientDrawable getgradiantThird() {
int[] colors1 = {Color.parseColor("#90CC57"), Color.parseColor("#46AF62")};
GradientDrawable gd1 = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors1);
gd1.setCornerRadius(10f);
return gd1;
}
int[] colors = {Color.parseColor("#F28542"), Color.parseColor("#F74368")};
GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors);
gd.setCornerRadius(20f);
return gd;
}
private GradientDrawable getgradiantFirst() {//3AA2E2
int[] colors1 = {Color.parseColor("#46AF62"), Color.parseColor("#3AA2E2")};//3AA2E2
GradientDrawable gd1 = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors1);
gd1.setCornerRadius(20f);
return gd1;
}
private GradientDrawable getgradiantSecond() {
int[] colors1 = {Color.parseColor("#EFB410"), Color.parseColor("#D14654")};
GradientDrawable gd1 = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors1);
gd1.setCornerRadius(20f);
return gd1;
}
private GradientDrawable getgradiantThird() {
int[] colors1 = {Color.parseColor("#90CC57"), Color.parseColor("#46AF62")};
GradientDrawable gd1 = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors1);
gd1.setCornerRadius(10f);
return gd1;
}
main_activity.xml
<LinearLayout
android:id="@+id/ll_main"
android:layout_width="300dp"
android:layout_height="400dp"
android:orientation="vertical">
android:layout_height="400dp"
android:orientation="vertical">
<TextView
android:layout_below="@+id/txtUserGameDate"
android:id="@+id/txtUserGameTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SAMSET
android:textColor="@color/white"
android:textSize="8sp"
android:textStyle="bold"
/>
android:layout_below="@+id/txtUserGameDate"
android:id="@+id/txtUserGameTime"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SAMSET
android:textColor="@color/white"
android:textSize="8sp"
android:textStyle="bold"
/>
</LinearLayout>
Thank you
No comments:
Post a Comment