F
F
freshcot2015-02-12 14:08:02
Java
freshcot, 2015-02-12 14:08:02

How to get layout color?

Hello, tell me how you can get the current color / background layout
Or tell me what it is by default if it is not set in the xml file
Thank you

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Flasher, 2015-02-12
@Flasher

One of the options

public class Enter {
  public static void main(String... args){
    new ColorLayout();
  }
}

import java.awt.*;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class ColorLayout extends JFrame{
  public ColorLayout() {
    this.add(new ColorPanel());
    this.setLocationRelativeTo(null);
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.setSize(new Dimension(200,200));
    this.setVisible(true);
  }
  
  public class ColorPanel extends JPanel{
    private JButton button;
    private JPanel buttonpanel;
    
    public ColorPanel() {
      buttonpanel = new JPanel();
      buttonpanel.setBackground(Color.decode("#eeeeee"));
      
      button = new JButton("Жми, чтобы узнать цвет");
      button.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
          System.out.println(buttonpanel.getBackground());
        }
      });
      
      buttonpanel.add(button);
      this.add(buttonpanel);
    }
  }
}

A
Alex_Tysel, 2015-02-13
@Alex_Tysel

To get the color of the layout set for the current activity, do:
View v = new View(this);
v.getSolidColor();
And by default, the background corresponds to the standard theme, which is written in the manifest.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question