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.
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.
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'sSharedPreferences
data and can modify it as well.
You can useSharedPreferences
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;
(orTextView
) intialize it in theonCreated()
asimageView = finViewById(R.id.viewId);
inSets
activity.
Call
it asnew SetsActivity().imageView.setBackgroundColor(yourColor);
inScoreActivity
.Second way is to create a public function in
SetsAcitvity
, putting the color change code in it, and then calling it from theScoreActivity
. Just declare it aspublic void changeColor(){ //your work}
and call it fromScoreActivity
asnew SetsActivity().changeCOlor()
. You can also pass some arguments to the function likesetId
.
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
Java.Io.Ioexception: Permission Denied Cannot Create File
How to Refresh a Previous Activity After the Back Button Is Pressed
How to Check Miui Autostart Permission Programmatically
Android: Open a Pdf from My App Using the Built in Pdf Viewer
How to Remove Focus Without Setting Focus to Another Control
Retrofit2 - How to Upload Image Using Retrofit in Multipart
How to Display Date Picker for Android With Only Month and Year Fields
How to Launch the Android Emulator from the Command Line
Fragment Is Not Being Replaced But Put on Top of the Previous One
How to Post Raw Whole Json in the Body of a Retrofit Request
React Native: Java_Home Is Not Set and No 'Java' Command Could Be Found in Your Path
How to Go Back to Previous Fragment from Activity
How to Set Transparency of a Background Image Android Xml File
Force Override Camera Image on Android
How to Prevent User Go Back to Protected Page After Logout
How to Make Primary Key as Autoincrement for Room Persistence Lib
Decrease Image Size Without Losing Its Quality in Android
How to Clear Navigation Stack After Navigating to Another Fragment in Android