FancyMenu Wiki/自定义菜单背景:修订间差异

// Edit via Wikiplus
(// Edit via Wikiplus)
 
(未显示同一用户的1个中间版本)
</syntaxhighlight>
====MenuBackgroundType Class====
创建一个<code>MenuBackgroundType</code>的新子类并给它取合适的名字。
 
接下来我会将我的示例背景类型类命名为<code>ExampleMenuBackgroundTypeWithInputString</code>
 
在这个类中有一些特别的点你需要留意。
=====构造方法(Constructor)=====
这里的构造方法用于设置你背景类型唯一的标识符。
<syntaxhighlight lang="java">
public ExampleMenuBackgroundTypeWithInputString() {
//This identifier needs to be UNIQUE! It is not possible to register multiple types with the same identifier.
super("example_type_input_string");
}
</syntaxhighlight>
复制代码
=====loadBackgrounds()=====
 
在输入字符串模式下,此方法未被使用,因为在此模式下,MenuBackground,<code>MenuBackground</code>实例会被即时创建。
loadBackgrounds()
<syntaxhighlight lang="java">
在输入字符串模式下,此方法未被使用,因为在此模式下,MenuBackground实例会被即时创建。
@Override
public void loadBackgrounds() {
//这里什么都没有是因为背景实例是通过createInstanceFromInputString()即时创建的。
}
</syntaxhighlight>
复制代码
=====getDisplayName()=====
 
getDisplayName()
调用此方法获取背景类型名。
 
名称显示在布局编辑器的背景选项中。
<syntaxhighlight lang="java">
//You don't really have much space for the display name, so try to choose a short one ond explain the type further in the description.
//显示名字的空间很挤,你的类型名字简短点吧,在描述里详细说明就好。
return "Example Type w/ Input";
}
</syntaxhighlight>
复制代码
=====getDescription()=====
 
getDescription()
获取背景类型的描述。
 
在布局编辑器的背景选项中显示。
<syntaxhighlight lang="java">
//Gets displayed when hovering over the type switcher in the background options menu in the layout editor.
//在布局编辑器的背景选项菜单中悬停在类型切换器上时显示。
return l;
}
</syntaxhighlight>
复制代码
=====needsInputString()=====
 
needsInputString()
这是最重要的方法,因为你得在这选择背景类型模式。
在这里,我们返回true,<code>true</code>,因为我们想为咱的背景类型使用输入字符串模式。
返回<code>false</code>会将背景类型设置为普通模式。
<syntaxhighlight lang="java">
@Override
public boolean needsInputString() {
return true;
}
</syntaxhighlight>
复制代码
=====createInstanceFromInputString()=====
当处于输入字符串模式时,每次需要一个新的<code>MenuBackground</code>实例时都会调用这个方法。
 
createInstanceFromInputString()
当处于输入字符串模式时,每次需要一个新的MenuBackground实例时都会调用这个方法。
它基本是菜单背景工厂。
 
这个方法有给定的输入字符串作为参数,所以你可以用它来创建新的实例。
<syntaxhighlight lang="java">
//In input string mode, this will get called whenever a new background instance is needed.
//在输入字符串模式下,每当需要一个新的背景实例时,它都会被调用。
return new ExampleMenuBackgroundForInputString(this, inputString);
}
</syntaxhighlight>
复制代码
=====onInputStringButtonPress()=====
 
onInputStringButtonPress()
这里,你可以指定当用户在布局编辑器的后台选项中点击输入字符串按钮时会发生什么。
 
在这基本没啥限制,除了让猴子写代码,想干啥干啥,只要你可以在最后正确地将新背景设置成编辑器实例。
<syntaxhighlight lang="java">
//This gets called when the input string button in the background options is pressed by the user.
//这个方法当用户按下背景选项上的输入字符串按钮后会被调用。
 
}
</syntaxhighlight>
复制代码
=====inputStringButtonLabel()=====
 
inputStringButtonLabel()
返回布局编辑器的背景选项中的输入字符串按钮的标签。
<syntaxhighlight lang="java">
//The button label of the input string button in the background options.
//背景选项中输入字符串按钮的按钮标签。
return "Choose File";
}
</syntaxhighlight>
复制代码
=====inputStringButtonTooltip()=====
 
inputStringButtonTooltip()
返回布局编辑器的背景选项中输入字符串按钮的工具提示。
<syntaxhighlight lang="java">
//A tooltip that gets displayed when hovering over the input string button in the background options menu of the layout editor.
//当悬停在布局编辑器的背景选项菜单的输入字符串按钮上时,会显示工具提示。
return l;
}
</syntaxhighlight>
复制代码
=====完整示例=====
 
完整示例
下面是完整的MenuBackgroundType样例.
<syntaxhighlight lang="java">
package de.keksuccino.fancymenu.api.background.example.with_input_string;
 
 
}
</syntaxhighlight>
复制代码
 
====注册菜单背景====
}
</syntaxhighlight>
[[分类:FancyMenu]]
维护员、​界面管理员、​巡查员、​监督员、​小部件编辑者
3,462

个编辑