How to create a custom theme and use it in an Android application?

后端 未结 3 1359
甜味超标
甜味超标 2021-02-01 07:52

How to create a custom themes and use it in the code?

In menu how to implement theme option and apply for the activity?

3条回答
  •  遥遥无期
    2021-02-01 08:13

    There's a nice Styles and Themes guide on the android developers site. Basically what you need to do is

    1. Define a style (or inherit a built-in one). To define a style

    save an XML file in the res/values/ directory of your project. The name of the XML file is arbitrary, but it must use the .xml extension and be saved in the res/values/ folder.

    The root node of the XML file must be .

    For each style you want to create, add a element to the file with a name that uniquely identifies the style (this attribute is required).

    i.e.

    
    
        
    
    

    It's useful to name the resource file themes.xml so it's easier to recognize what those styles are used for.

    1. Apply the defined style to the activity or view that you want stylized. You can either

      • set the Activity/Application theme in the manifest file:

      • or set it dynamically - use the corresponding setter of the Activity class - setTheme().

提交回复
热议问题