So I got following problem:
I'm currently developing a sensor app and I'd like to check if the sensors are available or not. If they aren't, I want to change the color of a button (which starts an activity where the value of the sensor is being displayed) to grey.
Sadly, I can't just change the background color of the button because I'm using the Circle Button Library by Markushi.
This button looks like this:
<at.markushi.ui.CircleButton
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#drawable/gyroscope"
app:cb_color="#color/colorMain"
app:cb_pressedRingWidth="8dip"
android:id="#+id/gyroscope"
android:layout_alignLeft="#+id/temperature"
android:layout_alignStart="#+id/temperature"
android:layout_below="#+id/title"/>
As you can see this attribute defines the color.
app:cb_color="#color/colorMain"
My Question is: How can I change this color programmaticly in this method?
public void testSensors() {
if (testManager.getDefaultSensor(Sensor.TYPE_TEMPERATURE) == null) {
}
}
EDIT:
setColor doesn't really work. There is this border left. (see image)
Also: I'm using #616161 as the new color.
EDIT2:
Found out, that the border is caused by the transparent circle thing which gets bigger, when the button is pressed. So basically removing this circle thing will be fine. I try to find an answer on my own :)
CircleButton button;
button = (Button)findViewById(R.id.buttonId);
public void testSensors() {
if (testManager.getDefaultSensor(Sensor.TYPE_TEMPERATURE) == null) {
button.setColor(Color.parse("#000000"));
}
}
If you are using normal button then
button.setBackgroundColor(ContextCompat.getColor(context,R.color.colorAccent));
You can use
1) Color.parse("#000000")
2) ContextCompat.getColor(context,R.color.yourColor)
You can use the setColor() method of the circleButton, as you can see from the source code here .
So basically what you need to do is get a reference to your circle Button, using the findViewById method of your activity. then
public void testSensors() {
if (testManager.getDefaultSensor(Sensor.TYPE_TEMPERATURE) == null) {
myCircleButton.setColor(Color.parse("#000000"));
}
}
Also if you are seeing the pressed ring, then that means the state of the button is somehow in the pressed state, so try setting it o false using the setPressed(false) method.
To answer this problem (if anyone has the same):
You can set the animation to 100. This somehow disables the circle.
For some reason the color of the button has now a fixed color (dark grey) but scince this is fine to me and I don't want to cry under my table, I just let it be and move on with my project.
mCircleButton.setAnimationProgress(100);
Thank you all so much for your help! :)
Related
I'm trying to update my theme with the new Material You, it's working when I select a color in Android parameter (Screenshot red part) but when I disable it (blue part) I've got the default value color set in the SDK xml.
Example with: #android:color/system_accent1_0
I want to know how to check when user select it or not (red or blue part in screenshot), this way i will use another theme when disable. I guess I need to use the new method: applyToActivitiesIfAvailable :
#Override
public void onCreate() {
super.onCreate();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
DynamicColors.applyToActivitiesIfAvailable(this, R.style.AppDynamicTheme, (activity, themeResId) -> {
// ...implement your own logic here. Return `true` if dynamic colors should be applied.
return true; // <- How to know if it's enable or disable in Android parameter ?
});}
My 2nd question is about the icon of the application, when i put blank color in background of ic_launcher.xml it works but not with another color, do you know why ?
Thanks
I have 4 simple buttons that interact with a listview. If you click a certain button you can go one down, one up, to the start and to the end of the listview. So each button has a different onAction method:
(Buttons: previous, next, end, start)
public void toNext(){
list.getSelectionModel().selectNext();
}
public void toPrevious(){
list.getSelectionModel().selectPrevious();
...
But now I want to disable the buttons if they can't go to the start, end, up or down. I tried to do the following by adding this code to the method toPrevious (example):
previous.setDisable(list.getSelectionModel().getSelectedIndex() == 0)
This code does disable the button but it won't enable it when you can go to the previous string in the listview. Does anyone has a simple solution for this?
You can use a binding:
previous.disableProperty().bind(
list.getSelectionModel().selectedIndexProperty().isEqualTo(0));
next.disableProperty().bind(
list.getSelectionModel().selectedIndexProperty().isEqualTo(
Bindings.size(list.getItems()).subtract(1)));
It is knowed that the StatusBar is black default of Andriod 4.2.
However,I want to make the StatusBar transparent on Launcher and change to be black when it come into an activity. And then,when it come back to the Launcher,the StatusBar recover to transparent.
There is a way to implement,but it do not work perfectly(the Activity open firstly and the StatusBar turn transparent slowly,No strict synchronization).
set "status_bar_background" to be #00000000;
delete the code "mStatusBarWindow.setBackground(null);" which in method "makeStatusBarView()" of PhoneStatusBar.java;
Edit mPixelFormat = PixelFormat.OPAQUE to mPixelFormat = PixelFormat.TRANSLUCENT;
change the code in WindowStateAnimator.java
updateSurfaceWindowCrop(), after the code line
"applyDecorRect(mService.mSystemDecorRect);"
Added:
if(w.mAttrs.type == LayoutParams.TYPE_WALLPAPER) {
w.mSystemDecorRect.top = 0;
}
I think cannot change StatusBar. If you want change, you has to change SystemUI
. You can references via link: http://forum.xda-developers.com/showthread.php?t=2366476
Hide the status bar and use you own header instead of it, best Solution.
I'm making minesweeper for a school project. When the player wins or loses, the mines are revealed. Their buttons are disabled, and icons of flags/mines will appear. The problem is that the icons turn grey when the buttons are disabled. Is there a way around this?
I have also tried setting the text of the JButton to something like "<html><img src=\"res\\mine.png\"/></html>" but it showed some weird image.
Update:
I tried using setDisabledIcon() but nothing's showing up. Here's some pseudo-code
The buttons I use for the minefield is a class called Field, which extends JButton
mouseReleased(mouseEvent e) {
Field fieldClicked = (Field)e.getSource();
if fieldClicked is mine {
fieldClicked.setEnabled(false);
gameTimer.stop();
setLost(true);
loop through 2D array of fields {
if field is a mine {
field.setDisabledIcon(Field.mineIcon);// public static final icon of Field. mineIcon = new ImageIcon("res\\mine.png")
field.setEnabled(false);
}
}
}
}
Figured this out in a test
For some reason
clickedButton.setDisabledIcon(mineIcon)
Alone doesn't do anything.
But:
clickedButton.setIcon(mineIcon)
clickedButton.setDisabledIcon(mineIcon)
Will show whatever icon I wanted
a JButton actually allows seven associated images: the main image (use
setIcon to specify it if not supplied in the constructor), the image
to use when the button is pressed (setPressedIcon), the image to use
when the mouse is over it (setRolloverIcon, but you need to call
setRolloverEnabled(true) first), the image to use when the button is
selected and enabled (setSelectedIcon), the image to use when the
button is disabled (setDisabledIcon), the image to use when it is
selected but disabled (setDisabledSelectedIcon), and the image to use
when the mouse is over it while it is selected
(setRolloverSelectedIcon).
- http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JButton.html
so use setDisabledIcon(ImageIcon)
The greyed image is the automatically generated one, in case you want a different icon, use setDisabledIcon()
Icon disabledIcon = new ImageIcon("youricon.gif");
button.setDisabledIcon(disabledIcon);
I apologize if this question is too basic, but I just can't figure out how to do this. I have a SWT TableFolder with two tabs, and I need to determine which of those two tabs are currently active, as it effects the behavior of another part of the program. Is this possible? Thank you in advance.
To you mean the org.eclipse.swt.widgets.TabFolder (CTabFolder)?
If yes add an eventlistener to your TabFolder(CTabFolder object
tabFolder.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent event) {
tabFolder.getSelection()[0]; // This should be your TabItem/CTabItem
}
});
If you simply have a javax.swing.JTabbedPane then calling
yourJTabbedPaneVariableName.getSelectedIndex()
gives you the index of the selected Tab