Abhay Jaiswal
Abhay Jaiswal

Reputation: 31

Use Custom XML Layout with GuidedStepSupportFragment For Smart TV UI Design

How can I use a custom xml layout file with GuidedStepSupportFragment with leanback library.

I need use the custom view into right and left both sides with some action. How can I achieve this? I am new to smart TV development.

I need some this type of more customized design :

enter image description here

Upvotes: 3

Views: 1464

Answers (1)

mahdi
mahdi

Reputation: 862

GuidedStepFragment is composed of 2 parts, Guidance (the side at left) and Actions (the side at right). You can provide layout for both of them by overriding onProvideLayoutId inside the corresponding Stylist.

For example if you want to change Guidance you can use this code:

    @Override
    public GuidanceStylist onCreateGuidanceStylist() {
        return new GuidanceStylist() {
            @Override
            public int onProvideLayoutId() {
                // return your cutom layout
                return R.layout.layout_custom_guidance;
            }

            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container, Guidance guidance) {
                View guidanceView = super.onCreateView(inflater, container, guidance);
                // You can access Views here
                return guidanceView;
            }
        };
    }

Actions part consists of several GuidedAction item, and for each you can provide the layout in a similar way:

    @Override
    public GuidedActionsStylist onCreateActionsStylist() {
        return new GuidedActionsStylist() {
            @Override
            public int onProvideItemLayoutId() {
                // return your custom layout for each GuidedAction item
                return R.layout.layout_custom_action_item;
            }

            @Override
            public ViewHolder onCreateViewHolder(ViewGroup parent) {
                ViewHolder viewHolder = super.onCreateViewHolder(parent);
                // Access Views here
                return viewHolder;
            }
        };
    }

For your specific Actions side you can insert one Action with your intended layout.

Upvotes: 4

Related Questions