Adding opacity to setStroke() programmatically
up vote
0
down vote
favorite
I am trying to set opacity to Border color using:
d.setStroke(5 , Color.parseColor("#4A000000"))
The result I get is a border with 50% dark color and 50% of opacity applied.
How to make that to blend like a normal background color, ColorUtils.setAlphaComponent(color, 100)
?
android alpha
add a comment |
up vote
0
down vote
favorite
I am trying to set opacity to Border color using:
d.setStroke(5 , Color.parseColor("#4A000000"))
The result I get is a border with 50% dark color and 50% of opacity applied.
How to make that to blend like a normal background color, ColorUtils.setAlphaComponent(color, 100)
?
android alpha
Why dont you like the border opacity at 50%? Can you explain what are you trying to achieve more precisely. Cant understand why the result of your code does not fit what you want.
– Ivan
Nov 8 at 11:15
I am trying to have a border with color and a variable alpha value, so that the border itself would get a transparency blended.
– pixelWorld
Nov 8 at 11:26
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to set opacity to Border color using:
d.setStroke(5 , Color.parseColor("#4A000000"))
The result I get is a border with 50% dark color and 50% of opacity applied.
How to make that to blend like a normal background color, ColorUtils.setAlphaComponent(color, 100)
?
android alpha
I am trying to set opacity to Border color using:
d.setStroke(5 , Color.parseColor("#4A000000"))
The result I get is a border with 50% dark color and 50% of opacity applied.
How to make that to blend like a normal background color, ColorUtils.setAlphaComponent(color, 100)
?
android alpha
android alpha
edited Nov 8 at 14:52
André Sousa
1,012818
1,012818
asked Nov 8 at 11:05
pixelWorld
86
86
Why dont you like the border opacity at 50%? Can you explain what are you trying to achieve more precisely. Cant understand why the result of your code does not fit what you want.
– Ivan
Nov 8 at 11:15
I am trying to have a border with color and a variable alpha value, so that the border itself would get a transparency blended.
– pixelWorld
Nov 8 at 11:26
add a comment |
Why dont you like the border opacity at 50%? Can you explain what are you trying to achieve more precisely. Cant understand why the result of your code does not fit what you want.
– Ivan
Nov 8 at 11:15
I am trying to have a border with color and a variable alpha value, so that the border itself would get a transparency blended.
– pixelWorld
Nov 8 at 11:26
Why dont you like the border opacity at 50%? Can you explain what are you trying to achieve more precisely. Cant understand why the result of your code does not fit what you want.
– Ivan
Nov 8 at 11:15
Why dont you like the border opacity at 50%? Can you explain what are you trying to achieve more precisely. Cant understand why the result of your code does not fit what you want.
– Ivan
Nov 8 at 11:15
I am trying to have a border with color and a variable alpha value, so that the border itself would get a transparency blended.
– pixelWorld
Nov 8 at 11:26
I am trying to have a border with color and a variable alpha value, so that the border itself would get a transparency blended.
– pixelWorld
Nov 8 at 11:26
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
You could use setStroke(),the second parameter is a ColorStateList
.
And each item in a ColorStateList
must define an android:color
attribute like below:
<item android:state_enabled="false"
android:color="?android:attr/colorAccent"
android:alpha="0.5" /> //use this xml attribute to set opacity.
Below is a complete ColorStateList
example:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:color="@color/sample_focused" />
<item android:state_pressed="true"
android:state_enabled="false"
android:color="@color/sample_disabled_pressed" />
<item android:state_enabled="false"
android:color="@color/sample_disabled_not_pressed" />
<item android:color="@color/sample_default"
android:alpha="0.5"/>
</selector>
After creating a ColorStateList
resource xml, use it in setStroke()
method.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You could use setStroke(),the second parameter is a ColorStateList
.
And each item in a ColorStateList
must define an android:color
attribute like below:
<item android:state_enabled="false"
android:color="?android:attr/colorAccent"
android:alpha="0.5" /> //use this xml attribute to set opacity.
Below is a complete ColorStateList
example:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:color="@color/sample_focused" />
<item android:state_pressed="true"
android:state_enabled="false"
android:color="@color/sample_disabled_pressed" />
<item android:state_enabled="false"
android:color="@color/sample_disabled_not_pressed" />
<item android:color="@color/sample_default"
android:alpha="0.5"/>
</selector>
After creating a ColorStateList
resource xml, use it in setStroke()
method.
add a comment |
up vote
0
down vote
You could use setStroke(),the second parameter is a ColorStateList
.
And each item in a ColorStateList
must define an android:color
attribute like below:
<item android:state_enabled="false"
android:color="?android:attr/colorAccent"
android:alpha="0.5" /> //use this xml attribute to set opacity.
Below is a complete ColorStateList
example:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:color="@color/sample_focused" />
<item android:state_pressed="true"
android:state_enabled="false"
android:color="@color/sample_disabled_pressed" />
<item android:state_enabled="false"
android:color="@color/sample_disabled_not_pressed" />
<item android:color="@color/sample_default"
android:alpha="0.5"/>
</selector>
After creating a ColorStateList
resource xml, use it in setStroke()
method.
add a comment |
up vote
0
down vote
up vote
0
down vote
You could use setStroke(),the second parameter is a ColorStateList
.
And each item in a ColorStateList
must define an android:color
attribute like below:
<item android:state_enabled="false"
android:color="?android:attr/colorAccent"
android:alpha="0.5" /> //use this xml attribute to set opacity.
Below is a complete ColorStateList
example:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:color="@color/sample_focused" />
<item android:state_pressed="true"
android:state_enabled="false"
android:color="@color/sample_disabled_pressed" />
<item android:state_enabled="false"
android:color="@color/sample_disabled_not_pressed" />
<item android:color="@color/sample_default"
android:alpha="0.5"/>
</selector>
After creating a ColorStateList
resource xml, use it in setStroke()
method.
You could use setStroke(),the second parameter is a ColorStateList
.
And each item in a ColorStateList
must define an android:color
attribute like below:
<item android:state_enabled="false"
android:color="?android:attr/colorAccent"
android:alpha="0.5" /> //use this xml attribute to set opacity.
Below is a complete ColorStateList
example:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:color="@color/sample_focused" />
<item android:state_pressed="true"
android:state_enabled="false"
android:color="@color/sample_disabled_pressed" />
<item android:state_enabled="false"
android:color="@color/sample_disabled_not_pressed" />
<item android:color="@color/sample_default"
android:alpha="0.5"/>
</selector>
After creating a ColorStateList
resource xml, use it in setStroke()
method.
answered Nov 8 at 11:23
navylover
2,39421117
2,39421117
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206468%2fadding-opacity-to-setstroke-programmatically%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Why dont you like the border opacity at 50%? Can you explain what are you trying to achieve more precisely. Cant understand why the result of your code does not fit what you want.
– Ivan
Nov 8 at 11:15
I am trying to have a border with color and a variable alpha value, so that the border itself would get a transparency blended.
– pixelWorld
Nov 8 at 11:26