android – 有没有简单的方法来创建一个Action Button片段?

android – 有没有简单的方法来创建一个Action Button片段?,第1张

概述 *** 作按钮是这样的: 我认为框架应该提供易于使用的片段,其中开发者只提供标题,图标,背景图像和监听器.我没有在文档中找到它,你知道吗? 我根据 design guidelines结束自己写的: ActionFragment.java public class ActionFragment extends Fragment implements View.OnClickListener { *** 作按钮是这样的:

我认为框架应该提供易于使用的片段,其中开发者只提供标题,图标,背景图像和监听器.我没有在文档中找到它,你知道吗?

解决方法 我根据 design guidelines结束自己写的:

ActionFragment.java

public class ActionFragment extends Fragment implements VIEw.OnClickListener {    private static Listener mListener;    private CircledImageVIEw vIcon;    private TextVIEw vLabel;    public static ActionFragment create(int iconResID,int labelResID,Listener Listener) {        mListener = Listener;        ActionFragment fragment = new ActionFragment();        Bundle args = new Bundle();        args.putInt("ICON",iconResID);        args.putInt("LABEL",labelResID);        fragment.setArguments(args);        return fragment;    }    @OverrIDe    public VIEw onCreateVIEw(LayoutInflater inflater,@Nullable VIEwGroup container,@Nullable Bundle savedInstanceState) {        return inflater.inflate(R.layout.fragment_action,container,false);    }    @OverrIDe    public voID onVIEwCreated(VIEw vIEw,@Nullable Bundle savedInstanceState) {        super.onVIEwCreated(vIEw,savedInstanceState);        vIcon = (CircledImageVIEw) vIEw.findVIEwByID(R.ID.icon);        vLabel = (TextVIEw) vIEw.findVIEwByID(R.ID.label);        vIcon.setimageResource(getArguments().getInt("ICON"));        vLabel.setText(getArguments().getInt("LABEL"));        vIEw.setonClickListener(this);    }    @OverrIDe    public voID onClick(VIEw v) {        mListener.onActionPerformed();    }    public interface Listener {        public voID onActionPerformed();    }}

布局/ fragment_action.xml

<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"              xmlns:app="http://schemas.androID.com/apk/res-auto"              xmlns:tools="http://schemas.androID.com/tools"              androID:orIEntation="vertical"              androID:paddingleft="16dp"              androID:paddingRight="16dp"              androID:paddingtop="24dp"              androID:paddingBottom="12dp"              androID:layout_wIDth="match_parent"              androID:layout_height="match_parent">    <androID.support.wearable.vIEw.CircledImageVIEw        androID:ID="@+ID/icon"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_g@R_301_6610@ty="center"        tools:src="@drawable/ic_full_cancel"        app:circle_color="@color/action_button"        app:circle_radius="52dp"        app:circle_border_wIDth="0dp"/>    <TextVIEw        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"        androID:g@R_301_6610@ty="center"        tools:text="Cancel"        androID:ID="@+ID/label"        androID:FontFamily="sans-serif-condensed-light"        androID:textSize="20sp"        androID:textcolor="@color/white"/></linearLayout>

彩色/ action_button.xml

<?xml version="1.0" enCoding="utf-8"?><selector xmlns:androID="http://schemas.androID.com/apk/res/androID">    <item androID:color="#2878ff" androID:state_pressed="false" />    <item androID:color="#2955C5" androID:state_pressed="true" /></selector>

使用示例(例如FragmentGrIDPagerAdapter)

ActionFragment.create(R.drawable.ic_full_open_on_phone,R.string.open_on_phone,new ActionFragment.Listener() {                    @OverrIDe                    public voID onActionPerformed() {                    }                });
总结

以上是内存溢出为你收集整理的android – 有没有简单的方法来创建一个Action Button片段?全部内容,希望文章能够帮你解决android – 有没有简单的方法来创建一个Action Button片段?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1131835.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存