美文网首页
改变菜单的字体的属性

改变菜单的字体的属性

作者: wslerz | 来源:发表于2016-09-13 09:06 被阅读0次

public static final int MI_FINISH = Menu.FIRST;
public static final int MI_ADDTASK = Menu.FIRST + 1;

 public boolean onCreateOptionsMenu(android.view.Menu menu) {
    menu.clear();
    setMenuBackground();
    menu.add(0, MI_FINISH, 0, "准备完成");
    menu.add(0, MI_ADDTASK, 0, "增加到标签");
    return true;
  }

  private void setMenuBackground() {
    // TODO Auto-generated method stub
    getLayoutInflater().setFactory(new Factory() {

        @Override
        public View onCreateView(final String name, final Context context,
                                 final AttributeSet attrs) {

  if(name.equalsIgnoreCase("com.android.internal.view.menu.IconMenuItemView")) {

                try { // Ask our inflater to create the view
                    final LayoutInflater f = getLayoutInflater();
                    final View[] view = new View[1];
                    try {
                        view[0] = f.createView(name, null, attrs);
                    } catch (InflateException e) {
                        chaneDeafultMenu(name, attrs, f, view);
                    }
                    // Kind of apply our own background
                    new Handler().post(new Runnable() {
                        @Override
                        public void run() {

                            ((TextView) view[0]).setTextColor(Color.WHITE);
                            ((TextView) view[0]).setTextSize(32F);
                            ((TextView) view[0])
                                    .setTypeface(Typeface.SANS_SERIF);
                        }
                    });
                    return view[0];
                } catch (InflateException e) {
                } catch (ClassNotFoundException e) {

                }
            }
            return null;
        }
    });
}

static void chaneDeafultMenu(final String name,
                             final android.util.AttributeSet attrs, final LayoutInflater f,
                             final View[] view) {
    // mConstructorArgs[0] is only non-null during a running call to
    // inflate()
    // so we make a call to inflate() and inside that call our dully
    // XmlPullParser get's called
    // and inside that it will work to call
    // "f.createView( name, null, attrs );"!
    try {
        f.inflate(new XmlPullParser() {
            @Override
            public int next() throws XmlPullParserException, IOException {
                try {
                    view[0] = f.createView(name, null, attrs);
                } catch (InflateException e) {
                } catch (ClassNotFoundException e) {
                }
                throw new XmlPullParserException("exit");
            }

            @Override
            public void defineEntityReplacementText(String arg0, String arg1)
                    throws XmlPullParserException {
                // TODO Auto-generated method stub

            }

            @Override
            public int getAttributeCount() {
                // TODO Auto-generated method stub
                return 0;
            }

            @Override
            public String getAttributeName(int arg0) {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public String getAttributeNamespace(int arg0) {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public String getAttributePrefix(int arg0) {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public String getAttributeType(int arg0) {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public String getAttributeValue(int arg0) {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public String getAttributeValue(String arg0, String arg1) {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public int getColumnNumber() {
                // TODO Auto-generated method stub
                return 0;
            }

            @Override
            public int getDepth() {
                // TODO Auto-generated method stub
                return 0;
            }

            @Override
            public int getEventType() throws XmlPullParserException {
                // TODO Auto-generated method stub
                return 0;
            }

            @Override
            public boolean getFeature(String arg0) {
                // TODO Auto-generated method stub
                return false;
            }

            @Override
            public String getInputEncoding() {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public int getLineNumber() {
                // TODO Auto-generated method stub
                return 0;
            }

            @Override
            public String getName() {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public String getNamespace() {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public String getNamespace(String arg0) {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public int getNamespaceCount(int arg0)
                    throws XmlPullParserException {
                // TODO Auto-generated method stub
                return 0;
            }

            @Override
            public String getNamespacePrefix(int arg0)
                    throws XmlPullParserException {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public String getNamespaceUri(int arg0)
                    throws XmlPullParserException {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public String getPositionDescription() {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public String getPrefix() {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public Object getProperty(String arg0) {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public String getText() {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public char[] getTextCharacters(int[] arg0) {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public boolean isAttributeDefault(int arg0) {
                // TODO Auto-generated method stub
                return false;
            }

            @Override
            public boolean isEmptyElementTag()
                    throws XmlPullParserException {
                // TODO Auto-generated method stub
                return false;
            }

            @Override
            public boolean isWhitespace() throws XmlPullParserException {
                // TODO Auto-generated method stub
                return false;
            }

            @Override
            public int nextTag() throws XmlPullParserException, IOException {
                // TODO Auto-generated method stub
                return 0;
            }

            @Override
            public String nextText() throws XmlPullParserException,
                    IOException {
                // TODO Auto-generated method stub
                return null;
            }

            @Override
            public int nextToken() throws XmlPullParserException,
                    IOException {
                // TODO Auto-generated method stub
                return 0;
            }

            @Override
            public void require(int arg0, String arg1, String arg2)
                    throws XmlPullParserException, IOException {
                // TODO Auto-generated method stub

            }

            @Override
            public void setFeature(String arg0, boolean arg1)
                    throws XmlPullParserException {
                // TODO Auto-generated method stub

            }

            @Override
            public void setInput(Reader arg0) throws XmlPullParserException {
                // TODO Auto-generated method stub

            }

            @Override
            public void setInput(InputStream arg0, String arg1)
                    throws XmlPullParserException {
                // TODO Auto-generated method stub

            }

            @Override
            public void setProperty(String arg0, Object arg1)
                    throws XmlPullParserException {
                // TODO Auto-generated method stub

            }
        }, null, false);
    } catch (InflateException e1) {
        // "exit" ignored
    }
}

相关文章

  • 改变菜单的字体的属性

    public static final int MI_FINISH = Menu.FIRST;public sta...

  • Sketch技巧-字体不显示中文解决

    菜单显示法 顶部菜单“查看”,“显示字体”。出来的字体在这里显示是中文,

  • NSAttributedString浅析

    NSFontAttributeName(字体) 该属性所对应的值是一个 UIFont 对象。该属性用于改变一段文本...

  • css 一些技巧

    鼠标选择字体时候改变颜色 和背景颜色 CSS3 filter(滤镜) 属性

  • 【CSS属性大全】

    CSS的文本属性 文本属性-字体风格 font-style:设置字体风格; 常用的属性:normal(常规字体)、...

  • ToolBar 封装及在 BaseActivity 和 Base

    ToolBar 常用属性和menu的使用及溢出菜单改变 请参考 ToolBar详解。 一、ToolBar 布局自定...

  • CSS文本样式

    CSS提供了几个属性来操作字体。font,可以很方便的指定字体的属性。比如: 字体加粗,字体的风格:斜体和字体变形...

  • 九、CSS字体属性与文本属性

    一、CSS字体属性与文本属性 1、CSS字体属性 CSS Fonts(字体)属性用于定义、大小、粗细、和文字样式(...

  • css3过渡和2D

    过度 过渡三要素1:需要有属性发生改变2:哪个属性需要发生改变3:过渡持续的时间 手风琴菜单 2D转换和形变中心点...

  • css中的继承属性和非继承属性

    继承属性 字体系列属性font:组合字体font-family:规定元素的字体系列font-weight:设置字体...

网友评论

      本文标题:改变菜单的字体的属性

      本文链接:https://www.haomeiwen.com/subject/oxrmettx.html