Removing Backgroundcolor of a View in Android

removing backgroundcolor of a view in android

You should try setting the background color to transparent:

view.setBackgroundColor(0x00000000);

Change background color of a view without removing drawable

This finally worked for me:

<ImageView
android:id="@+id/view_background"
android:layout_width="@dimen/width"
android:layout_height="@dimen/height"
android:src="@xml/button_round_corner_default_shape" />

<View
android:layout_width="@dimen/width"
android:layout_height="@dimen/height"
android:background="@xml/my_drawable" />

And in the code:

viewBackground = findViewById<ImageView>(Resource.Id.view_background);
viewBackground.setColorFilter(color);

I combined pieces of everyone's answer to do this.

View's Background Color Removed When Using RelativeLayout In ListView

You have duplicate 'notebook_color_tag' ID's. You are adding it twice in the first layout XML (as a parameter in the TextView and also as a child of the layout).

Also, I would reverse the order, like so:


<View
android:id="@+id/notebook_color_tag"
android:layout_width="20dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
/>

<TextView
android:id="@+id/notebook_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:textAppearanceLarge"
android:layout_toRightOf="@id/notebook_color_tag"
/>

Since the RelativeLayout will create and place in the order of the XML, this is more efficient (it does not have to remeasure to place the views correctly.

How to change the background color of a view from a different activity in android?

As your activity Sequence is MainActivity -> Categories -> Sets -> Scores.

You've two options to change the color with two different life cycle of the change.

  1. To change the color on a temporary basis, this will reset itself after closing the app or resrtating the 'Sets' activity. It can be done in two ways: Using Public Static Variable and using a public function.

  2. To change the color on a permanent basis until the app is uninstalled/reinstalled. You should use SharedPreferences. SharedPreferences acts like a private data stored in device's memory for further use and it stays there unchanged until and unless the app is removed/data is cleared. Although, apps with root permission can access any app's SharedPreferences data and can modify it as well.
    You can use SharedPreferences as explained here. Or, you can use some library to access it an easy way. The way I use it in all my apps is TinyDB(it's just a java/kotlin file). This works as:

    //store the value from ScoreActivity after completion as

    TinyDB tinyDB = TinyDB(this);
    tinyDB.putBoolean("isSet1Completed",true);

    //access the boolean variable in SetsActivity to change the color of any set that
    //is completed and if it's true, just change the color.

    TinyDB tinyDB = TinyDB(this);
    Boolean bool1 = tinyDB.getBoolean("isSet1Completed");

But, it's your choice what way you want to prefer.
Now, this was about the lifecycle of the change you'll do: Temp or Permanent. Now, we'll talk about how you change the color.

  • Using public static variable in Sets activity. What you can do is you can set the imageView/textview whose background you want to change as public static variable. Remember, this idea is not preferred as it causes memory leak but it's just easy.

    Declare it as public static ImageView imageview;(or TextView) intialize it in the
    onCreated() as imageView = finViewById(R.id.viewId); in Sets activity.
    Call
    it as new SetsActivity().imageView.setBackgroundColor(yourColor); in ScoreActivity.

  • Second way is to create a public function in SetsAcitvity, putting the color change code in it, and then calling it from the ScoreActivity. Just declare it as public void changeColor(){ //your work} and call it from ScoreActivity as new SetsActivity().changeCOlor(). You can also pass some arguments to the function like setId.

I've provided you every thing you need. Rest you should figure out yourself to actually learn it and not copy it.

How to remove global background color from a activity android

In my case, I created the other general theme: without_background_color_theme and move all your attributes to this theme except background color. Then your background color theme will extend without_background_color_theme. Now you can set the Activity's theme which you want to unset background color to without_background_color_theme.

<style name="background_color_theme" parent="without_background_color_theme>
<item name="android:windowBackground">@color/custom_theme_color</item>
<item name="android:colorBackground">@color/custom_theme_color</item>
</style>

Remove the Top and Bottom background color of Dropdown Items

Try to apply background drawable programmatically like below:

autoCompleteTextView.setDropDownBackgroundDrawable(
context.getResources().getDrawable(R.drawable.yellow_drawable));

Create yellow_drawable.xml with solid yellow color.

Remove background drawable programmatically in Android

Try this

RelativeLayout relative = (RelativeLayout) findViewById(R.id.widget29);
relative.setBackgroundResource(0);

Check the setBackground functions in the RelativeLayout documentation



Related Topics



Leave a reply



Submit