高仿QQ主界面

 先看效果图:


下面三个TAB,第一个消息TAB上面又有两个TAB,很显然下面是三个Fragment,这里推荐两篇文章,关于TAB主界面必看:

郭霖:Android Fragment应用实战,使用碎片向ActivityGroup说再见

鸿洋:Android项目Tab类型主界面大总结 Fragment+TabPageIndicator+ViewPager

MainActivity布局文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:orientation="vertical"
   >

    <FrameLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="0dp">
    </FrameLayout>
    <include
        layout="@layout/bottom"/>
</LinearLayout>

FrameLayout 加载fragment,bottom 就是底部栏,如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="#ffffffff"
    android:orientation="vertical"
    >

    <View
        android:layout_width="match_parent"
        android:layout_height="1px"
        android:background="#FFDEDEDE" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical"
    android:orientation="horizontal"
    >
        <LinearLayout
            android:id="@+id/message_layout"
            android:layout_height="wrap_content"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/message_image"
                android:layout_width="25dp"
                android:layout_height="25dp"
                android:layout_gravity="center_horizontal"
                android:background="@drawable/msg_img_selector"
                />

            <TextView
                android:id="@+id/message_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:gravity="center"
                android:text="消息"
                android:textColor="#82858b" />
        </LinearLayout>


        <LinearLayout
            android:id="@+id/contacts_layout"
            android:layout_height="wrap_content"
            android:layout_width="0dp"
            android:layout_centerVertical="true"
            android:layout_weight="1"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/contacts_image"
                android:layout_width="25dp"
                android:layout_height="25dp"
                android:layout_gravity="center_horizontal"
                android:src="@drawable/contact_img_selector" />

            <TextView
                android:id="@+id/contacts_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:text="联系人"
                android:textColor="#82858b" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/news_layout"
             android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:layout_centerVertical="true"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/news_image"
                android:layout_width="25dp"
                android:layout_height="25dp"
                android:layout_gravity="center_horizontal"
                android:src="@drawable/news_img_selector" />

            <TextView
                android:id="@+id/news_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:text="动态"
                android:textColor="#82858b" />
        </LinearLayout>
 </LinearLayout>
</LinearLayout>

并附上相应的图片selector:

<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- 默认时的背景图片-->

    <!-- 没有焦点时的背景图片 -->
    <!-- 非触摸模式下获得焦点并单击时的背景图片 -->
    <item android:state_focused="true" android:state_pressed="true"   android:drawable= "@mipmap/msg_selected" />
    <!-- 触摸模式下单击时的背景图片-->
    <item android:state_focused="false" android:state_pressed="true"   android:drawable="@mipmap/msg_selected" />
    <!--选中时的图片背景-->
    <item android:state_selected="true"   android:drawable="@mipmap/msg_selected" />
    <item android:drawable="@mipmap/msg_unselected" />
</selector>


用selector好处就是直接调用View.setSelected来处理选中未选中的状态,这里不多述。

下面三个TAB,是fragment组成的,上面两个TAB呢?由于界面比较简单,我这里用ViewPager包裹两个View解决,通过切换TAB选择相应的页面,但是ViewPager是支持滑动的,而QQ是不能滑动的,这样的话,需要重写ViewPager,自定义一个NoTouchViewPager继承ViewPager,如下:

package com.dhl.qqmsgtab.ui;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

/**
 * Created by dhl on 2017/5/1.
 * 不可以滑动的ViewPager
 */

public class NoTouchViewPager  extends ViewPager{
    public NoTouchViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public NoTouchViewPager(Context context) {
        super(context);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        return false;
    }

    @Override
    public void setCurrentItem(int item) {
        super.setCurrentItem(item,false);
    }
}
通过重写onTouchEvent,返回FALSE,让它不能滑动。

消息页面布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
   >

    <include
        android:id="@+id/top_layout"
        layout="@layout/top"/>

    <com.dhl.qqmsgtab.ui.NoTouchViewPager
        android:id="@+id/view_page"
        android:layout_below="@id/top_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </com.dhl.qqmsgtab.ui.NoTouchViewPager>

</RelativeLayout>


消息页面上面的TAB,包含消息和电话的布局top:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="@color/colorPrimary"
    android:orientation="vertical"
    android:gravity="center"
    >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="30dp"
    android:gravity="center"
    android:layout_gravity="center"
    android:orientation="horizontal"
    >

    <TextView
                android:id="@+id/message_text"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center"
                android:gravity="center"
                android:background="@drawable/top_msg_selector"
                android:text="消息"
                android:textColor="@color/top_msg_color_selector" />

    <TextView
        android:id="@+id/phone_text"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:background="@drawable/top_msg_selector"
        android:gravity="center"
        android:text="电话"
        android:textColor="@color/top_msg_color_selector" />

 </LinearLayout>
</LinearLayout>

通过下面的方法来选择相应的TAB:

/**
     * 选择相应的TAB
     * @param view
     */
    private void changeSelector(View view)
    {
        currentBtn.setSelected(false);
        view.setSelected(true);
        currentBtn = view;
    }

消息Fragment的界面:

public class MessageFragment extends Fragment implements View.OnClickListener {
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String TAG = MessageFragment.class.getSimpleName();
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;

    private TextView msgText ;
    private TextView phoneText ;
    private View currentBtn ;
    private NoTouchViewPager viewPager ;
    private List<View> tabView ;
    private OnFragmentInteractionListener mListener;

    public MessageFragment() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment MessageFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static MessageFragment newInstance(String param1, String param2) {
        MessageFragment fragment = new MessageFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_message, container, false);
        initId(view);
        return view;
    }
    private void initId(View view)
    {
        msgText = (TextView)view.findViewById(R.id.message_text);
        msgText.setOnClickListener(this);
        currentBtn = msgText ;
        phoneText = (TextView)view.findViewById(R.id.phone_text);
        phoneText.setOnClickListener(this);
        viewPager = (NoTouchViewPager) view.findViewById(R.id.view_page);
        tabView = new ArrayList<>();
        LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
        View pageMsg = layoutInflater.inflate(R.layout.page_msg,null);
        View pagPhone = layoutInflater.inflate(R.layout.page_phone,null);
        tabView.add(pageMsg);
        tabView.add(pagPhone);
        viewPager.setAdapter(new PagerAdapter() {
            @Override
            public Object instantiateItem(ViewGroup container, int position) {
                Log.e(TAG,container.toString()+"::::::"+viewPager.toString());
                //container 就是ViewPager
                viewPager.addView(tabView.get(position));
                return tabView.get(position);
            }

            @Override
            public int getCount() {
                return tabView.size();
            }

            @Override
            public boolean isViewFromObject(View view, Object object) {
                return view == object;
            }
        });
        //tabViewmsgText.setSelected(true);
        changeSelector(msgText);
    }

    // TODO: Rename method, update argument and hook method into UI event
    public void onButtonPressed(Uri uri) {
        if (mListener != null) {
            mListener.onFragmentInteraction(uri);
        }
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mListener = null;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId())
        {
            case R.id.message_text:
                changeSelector(msgText);
                viewPager.setCurrentItem(0);
                break;
            case R.id.phone_text:
                changeSelector(phoneText);
                viewPager.setCurrentItem(1);
                break;
        }
    }

    /**
     * This interface must be implemented by activities that contain this
     * fragment to allow an interaction in this fragment to be communicated
     * to the activity and potentially other fragments contained in that
     * activity.
     * <p>
     * See the Android Training lesson <a href=
     * "http://developer.android.com/training/basics/fragments/communicating.html"
     * >Communicating with Other Fragments</a> for more information.
     */
    public interface OnFragmentInteractionListener {
        // TODO: Update argument type and name
        void onFragmentInteraction(Uri uri);
    }

    /**
     * 选择相应的TAB
     * @param view
     */
    private void changeSelector(View view)
    {
        currentBtn.setSelected(false);
        view.setSelected(true);
        currentBtn = view;
    }

}
相应MainActivity的代码:

public class  MainActivity extends AppCompatActivity  implements  View.OnClickListener {

    private MessageFragment messageFragment ;

    private ContactFragment contactFragment ;

    private NewsFragment newsFragment ;

    private FragmentManager fragmentManager ;

    /**
     * 消息界面布局
     */
    private View messageLayout;

    /**
     * 联系人界面布局
     */
    private View contactsLayout;

    /**
     * 动态界面布局
     */
    private View newsLayout;

    /**
     * 设置界面布局
     */
    private View settingLayout;

    /**
     * 在Tab布局上显示消息图标的控件
     */
    private ImageView messageImage;

    /**
     * 在Tab布局上显示联系人图标的控件
     */
    private ImageView contactsImage;

    /**
     * 在Tab布局上显示动态图标的控件
     */
    private ImageView newsImage;


    /**
     * 在Tab布局上显示消息标题的控件
     */
    private TextView messageText;

    /**
     * 在Tab布局上显示联系人标题的控件
     */
    private TextView contactsText;

    /**
     * 在Tab布局上显示动态标题的控件
     */
    private TextView newsText;

    /**
     * 在Tab布局上显示设置标题的控件
     */
    private TextView settingText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        /**
         * 隐藏标题栏
         */
        ActionBar actionBar = getSupportActionBar();
        actionBar.hide();
        initViews();
        setTab(0);

    }

    private void initViews()
    {
        messageLayout = (LinearLayout)findViewById(R.id.message_layout);
        contactsLayout = (LinearLayout)findViewById(R.id.contacts_layout);
        newsLayout = (LinearLayout)findViewById(R.id.news_layout);
        messageImage = (ImageView)findViewById(R.id.message_image);
        contactsImage = (ImageView)findViewById(R.id.contacts_image);
        newsImage = (ImageView)findViewById(R.id.news_image);
        messageLayout.setOnClickListener(this);
        contactsLayout.setOnClickListener(this);
        newsLayout.setOnClickListener(this);
    }

    /**
     * 选择相应的Tab
     * @param index
     */

    private void setTab(int index)
    {
        fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        hideFragments(fragmentTransaction);
        clearSelcetor();
        switch (index)
        {
            case 0:
                messageImage.setSelected(true);
                if(messageFragment==null)
                {
                    messageFragment = MessageFragment.newInstance("","");
                    fragmentTransaction.add(R.id.content,messageFragment);
                }else
                {
                    fragmentTransaction.show(messageFragment);
                }
                break;
            case 1:
                contactsImage.setSelected(true);
                if(contactFragment == null)
                {
                    contactFragment = ContactFragment.newInstance("","");
                    fragmentTransaction.add(R.id.content,contactFragment);

                }else
                {
                    fragmentTransaction.show(contactFragment);
                }
                break;
            case 2:
                newsImage.setSelected(true);
                if(newsFragment == null)
                {
                    newsFragment = NewsFragment.newInstance("","");
                    fragmentTransaction.add(R.id.content,newsFragment);
                }else
                {
                    fragmentTransaction.show(newsFragment);
                }
                break;

        }
        fragmentTransaction.commit();

    }

    /**
     * 将所有的Fragment都置为隐藏状态。
     *
     * @param transaction
     *            用于对Fragment执行操作的事务
     */
    private void hideFragments(FragmentTransaction transaction) {
        if (messageFragment != null) {
            transaction.hide(messageFragment);
        }
        if (contactFragment != null) {
            transaction.hide(contactFragment);
        }
        if (newsFragment != null) {
            transaction.hide(newsFragment);
        }

    }
    @Override
    public void onClick(View view) {
        switch(view.getId())
        {
            case R.id.message_layout:
                setTab(0);
                break;
            case R.id.contacts_layout:
                setTab(1);
                break;
            case R.id.news_layout:
                setTab(2);
                break;
        }
    }

    /**
     * 全部未选中
     */
    private void clearSelcetor()
    {
        messageImage.setSelected(false);
        contactsImage.setSelected(false);
        newsImage.setSelected(false);
    }
}

源码: 高仿QQTab

最后附上图片来源网址:tab图片

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
高仿QQ聊天 登录界面 import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JScrollPane; import javax.swing.JTextField; import javax.swing.JTextPane; import javax.swing.UIManager; import javax.swing.text.BadLocationException; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; import javax.swing.text.StyledDocument; public class Test extends JFrame { private JScrollPane scrollPane = null; // 滚动 private JTextPane text = null; private Box box = null; // 放输入组件的容器 private JButton b_insert = null, b_remove = null, b_icon = null; // 插入按钮;清除按钮;插入图片按钮 private JTextField addText = null; // 文字输入框 // 字体名称;字号大小;文字样式;文字颜色;文字背景颜色 private JComboBox fontName = null, fontSize = null, fontStyle = null, fontColor = null, fontBackColor = null; private StyledDocument doc = null; // 非常重要插入文字样式就靠它了 public Test() { super("JTextPane Test"); try { // 使用Windows的界面风格 UIManager.setLookAndFeel ("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception e) { e.printStackTrace(); } text = new JTextPane(); text.setEditable(false); // 不可录入 doc = text.getStyledDocument(); // 获得JTextPane的Document scrollPane = new JScrollPane(text); addText = new JTextField(18); String[] str_name = { "宋体", "黑体", "Dialog", "Gulim" }; String[] str_Size = { "12", "14", "18", "22", "30", "40" }; String[] str_Style = { "常规", "斜体", "粗体", "粗斜体" }; String[] str_Color = { "黑色", "红色", "蓝色", "黄色", "绿色" }; String[] str_BackColor = { "无色", "灰色", "淡红", "淡蓝", "淡黄", "淡绿" }; fontName = new JComboBox(str_name); // 字体名称 fontSize = new JComboBox(str_Size); // 字号 fontStyle = new JComboBox(str_Style); // 样式 fontColor = new JComboBox(str_Color); // 颜色 fontBackColor = new JComboBox(str_BackColor); // 背景颜色 b_insert = new JButton("插入"); // 插入 b_remove = new JButton("清空"); // 清除 b_icon = new JButton("图片"); // 插入图片 b_insert.addActionListener(new ActionListener() { // 插入文字的事件 public void actionPerformed(ActionEvent e) { insert(getFontAttrib()); addText.setText(""); } }); b_remove.addActionListener(new ActionListener() { // 清除事件 public void actionPerformed(ActionEvent e) { text.setText(""); } }); b_icon.addActionListener(new ActionListener() { // 插入图片事件 public void actionPerformed(ActionEvent arg0) { JFileChooser f = new JFileChooser(); // 查找文件 f.showOpenDialog(null); insertIcon(f.getSelectedFile()); // 插入图片 } }); box = Box.createVerticalBox(); // 竖结构 Box box_1 = Box.createHorizontalBox(); // 横结构 Box box_2 = Box.createHorizontalBox(); // 横结构 box.add(box_1); box.add(Box.createVerticalStrut(8)); // 两行的间距 box.add(box_2); box.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); // 8个的边距 // 开始将所需组件加入容器 box_1.add(new JLabel("字体:")); // 加入标签 box_1.add(fontName); // 加入组件 box_1.add(Box.createHorizontalStrut(8)); // 间距 box_1.add(new JLabel("样式:")); box_1.add(fontStyle); box_1.add(Box.createHorizontalStrut(8)); box_1.add(new JLabel("字号:")); box_1.add(fontSize); box_1.add(Box.createHorizontalStrut(8)); box_1.add(new JLabel("颜色:")); box_1.add(fontColor); box_1.add(Box.createHorizontalStrut(8)); box_1.add(new JLabel("背景:")); box_1.add(fontBackColor); box_1.add(Box.createHorizontalStrut(8)); box_1.add(b_icon); box_2.add(addText); box_2.add(Box.createHorizontalStrut(8)); box_2.add(b_insert); box_2.add(Box.createHorizontalStrut(8)); box_2.add(b_remove); this.getRootPane().setDefaultButton(b_insert); // 默认回车按钮 this.getContentPane().add(scrollPane); this.getContentPane().add(box, BorderLayout.SOUTH); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(600, 400); this.setLocationRelativeTo(null); this.setVisible(true); addText.requestFocus(); } /** * 插入图片 * * @param icon */ private void insertIcon(File file) { text.setCaretPosition(doc.getLength()); // 设置插入位置 text.insertIcon(new ImageIcon(file.getPath())); // 插入图片 insert(new FontAttrib()); // 这样做可以换行 } /** * 将文本插入JTextPane * * @param attrib */ private void insert(FontAttrib attrib) { try { // 插入文本 doc.insertString(doc.getLength(), attrib.getText() + "\n", attrib.getAttrSet()); } catch (BadLocationException e) { e.printStackTrace(); } } /** * 获取所需要的文字设置 * * @return FontAttrib */ private FontAttrib getFontAttrib() { FontAttrib att = new FontAttrib(); att.setText(addText.getText()); att.setName((String) fontName.getSelectedItem()); att.setSize(Integer.parseInt((String) fontSize.getSelectedItem())); String temp_style = (String) fontStyle.getSelectedItem(); if (temp_style.equals("常规")) { att.setStyle(FontAttrib.GENERAL); } else if (temp_style.equals("粗体")) { att.setStyle(FontAttrib.BOLD); } else if (temp_style.equals("斜体")) { att.setStyle(FontAttrib.ITALIC); } else if (temp_style.equals("粗斜体")) { att.setStyle(FontAttrib.BOLD_ITALIC); } String temp_color = (String) fontColor.getSelectedItem(); if (temp_color.equals("黑色")) { att.setColor(new Color(0, 0, 0)); } else if (temp_color.equals("红色")) { att.setColor(new Color(255, 0, 0)); } else if (temp_color.equals("蓝色")) { att.setColor(new Color(0, 0, 255)); } else if (temp_color.equals("黄色")) { att.setColor(new Color(255, 255, 0)); } else if (temp_color.equals("绿色")) { att.setColor(new Color(0, 255, 0)); } String temp_backColor = (String) fontBackColor.getSelectedItem(); if (!temp_backColor.equals("无色")) { if (temp_backColor.equals("灰色")) { att.setBackColor(new Color(200, 200, 200)); } else if (temp_backColor.equals("淡红")) { att.setBackColor(new Color(255, 200, 200)); } else if (temp_backColor.equals("淡蓝")) { att.setBackColor(new Color(200, 200, 255)); } else if (temp_backColor.equals("淡黄")) { att.setBackColor(new Color(255, 255, 200)); } else if (temp_backColor.equals("淡绿")) { att.setBackColor(new Color(200, 255, 200)); } } return att; } public static void main(String args[]) { new Test(); } /** * 字体的属性类 */ private class FontAttrib { public static final int GENERAL = 0; // 常规 public static final int BOLD = 1; // 粗体 public static final int ITALIC = 2; // 斜体 public static final int BOLD_ITALIC = 3; // 粗斜体 private SimpleAttributeSet attrSet = null; // 属性集 private String text = null, name = null; // 要输入的文本和字体名称 private int style = 0, size = 0; // 样式和字号 private Color color = null, backColor = null; // 文字颜色和背景颜色 /** * 一个空的构造(可当做换行使用) */ public FontAttrib() { } /** * 返回属性集 * * @return */ public SimpleAttributeSet getAttrSet() { attrSet = new SimpleAttributeSet(); if (name != null) StyleConstants.setFontFamily(attrSet, name); if (style == FontAttrib.GENERAL) { StyleConstants.setBold(attrSet, false); StyleConstants.setItalic(attrSet, false); } else if (style == FontAttrib.BOLD) { StyleConstants.setBold(attrSet, true); StyleConstants.setItalic(attrSet, false); } else if (style == FontAttrib.ITALIC) { StyleConstants.setBold(attrSet, false); StyleConstants.setItalic(attrSet, true); } else if (style == FontAttrib.BOLD_ITALIC) { StyleConstants.setBold(attrSet, true); StyleConstants.setItalic(attrSet, true); } StyleConstants.setFontSize(attrSet, size); if (color != null) StyleConstants.setForeground(attrSet, color); if (backColor != null) StyleConstants.setBackground(attrSet, backColor); return attrSet; } /** * 设置属性集 * * @param attrSet */ public void setAttrSet(SimpleAttributeSet attrSet) { this.attrSet = attrSet; } /* 后面的注释就不写了,一看就明白 */ public String getText() { return text; } public void setText(String text) { this.text = text; } public Color getColor() { return color; } public void setColor(Color color) { this.color = color; } public Color getBackColor() { return backColor; } public void setBackColor(Color backColor) { this.backColor = backColor; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getSize() { return size; } public void setSize(int size) { this.size = size; } public int getStyle() { return style; } public void setStyle(int style) { this.style = style; } } }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值