<span id="Label3"></p><p><p>I wonder if you have customized UI templates in actual development? Take the time today to study the custom UI templates in Android and share them with YOU.<br>Every well-designed app is a custom title bar, and in the process of customizing the title bar, Most people may be customizing a header XML file, and then referencing it directly through include where needed, which is much more evolved than writing the title bar in each layout file. But it's still not the simplest and most effective way, why can't we customize a header control? Today you can make a title bar control for Yourself. As follows:</p></p><p><p></p></p><p><p>Here we go:</p></p><p><p><strong>First Step: customizing XML properties</strong></p></p><p><p>Create a new Android project, create a new Atts.xml file in the values folder, and declare in this XML file the properties we will need to specify when using the custom Control.<br>Atts.xml</p></p><pre class="prettyprint"><code class=" hljs xml"><span class="hljs-pi"><span class="hljs-pi"><?xml version= "1.0" encoding= "utf-8"?></span></span><span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-title">resources</span>></span></span> <span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-title">declare-styleable</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"ToolBar"</span>></span></span> <span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-title">attr</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"title"</span> <span class="hljs-attribute">format</span>=<span class="hljs-value">"string"</span> /></span></span> <span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-title">attr</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"titletextsize"</span> <span class="hljs-attribute">format</span>=<span class="hljs-value">"dimension"</span> /></span></span> <span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-title">attr</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"titletextcolor"</span> <span class="hljs-attribute">format</span>=<span class="hljs-value">"color"</span> /> </span></span> <span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-title">attr</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"leftbackground"</span> <span class="hljs-attribute">format</span>=<span class="hljs-value">"reference|color"</span> /> </span></span> <span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-title">attr</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"lefttext"</span> <span class="hljs-attribute">format</span>=<span class="hljs-value">"string"</span> /></span></span> <span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-title">attr</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"lefttextcolor"</span> <span class="hljs-attribute">format</span>=<span class="hljs-value">"reference|color" </span>/></span></span> <span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-title">attr</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"rightbackground"</span> <span class="hljs-attribute">format</span>=<span class="hljs-value">"reference|color"</span> /> </span></span> <span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-title">attr</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"righttext"</span> <span class="hljs-attribute">format</span>=<span class="hljs-value">"string"</span> /></span></span> <span class="hljs-tag"><span class="hljs-tag"><<span class="hljs-title">attr</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"righttextcolor"</span> <span class="hljs-attribute">format</span>=<span class="hljs-value">"reference|color" </span>/></span></span> <span class="hljs-tag"><span class="hljs-tag"></<span class="hljs-title">declare-styleable</span>></span></span><span class="hljs-tag"><span class="hljs-tag"></<span class="hljs-title">Resources</span>></span></span></code></pre><p><p>The previous name is the name of the property we want to use, followed by format, which indicates that the property accepts a value that is a string, that the value of the property is a color value, and that dimension indicates that the value of the property is a dimension, Reference indicates that the value of this property can refer to a resource id, and other common format values are: boolean (boolean), float (floating point value), integer (integer value), fraction (percent), enum (enumeration value), Flag (bit or operation).</p></p><p><p><strong>Step two: Customize the title class</strong><br>In the Java file to customize a class to inherit relativelayout, and implement its construction method, our title bar consists of three parts, the left and right sides are a button, the middle is a textview, So what we're going to do in this layout file is to handle the three Controls.</p></p><p><p>First declare the title bar of three space and related parameters, These parameters are set according to atts.xml, because we reference the custom control is from the XML reference, the property is set in the XML file, we get the value of the property from the XML file, and then set the value of the Control.</p></p><pre class="prettyprint"><code class=" hljs java"> <span class="hljs-javadoc"><span class="hljs-javadoc">/** * Three controls in title bar</span> */</span> <span class="hljs-keyword"><span class="hljs-keyword">Private</span></span>Button leftbtn, rightbtn;<span class="hljs-keyword"><span class="hljs-keyword">Private</span></span>TextView title;<span class="hljs-javadoc"><span class="hljs-javadoc">/** * Properties of the left button *</span> /</span> <span class="hljs-keyword"><span class="hljs-keyword">Private</span></span> <span class="hljs-keyword"><span class="hljs-keyword">int</span></span>lefttextcolor;<span class="hljs-keyword"><span class="hljs-keyword">Private</span></span>Drawable leftbackground;<span class="hljs-keyword"><span class="hljs-keyword">Private</span></span>String lefttext;<span class="hljs-javadoc"><span class="hljs-javadoc">/** * Properties of the right button *</span> /</span> <span class="hljs-keyword"><span class="hljs-keyword">Private</span></span> <span class="hljs-keyword"><span class="hljs-keyword">int</span></span>righttextcolor;<span class="hljs-keyword"><span class="hljs-keyword">Private</span></span>Drawable rightbackground;<span class="hljs-keyword"><span class="hljs-keyword">Private</span></span>String righttext;<span class="hljs-javadoc"><span class="hljs-javadoc">/** * Attributes of intermediate TextView *</span> /</span> <span class="hljs-keyword"><span class="hljs-keyword">Private</span></span> <span class="hljs-keyword"><span class="hljs-keyword">int</span></span>titletextcolor;<span class="hljs-keyword"><span class="hljs-keyword">Private</span></span>String titletext;<span class="hljs-keyword"><span class="hljs-keyword">Private</span></span> <span class="hljs-keyword"><span class="hljs-keyword">float</span></span>titletextsize;<span class="hljs-javadoc"><span class="hljs-javadoc">/** * Layout parameters for three controls *</span> /</span> <span class="hljs-keyword"><span class="hljs-keyword">Private</span></span>Layoutparams leftparams, rightparams, titleparams;</code></pre><p><p>Here is the constructor method, which constructs a method to pass in two parameters, one is the context parameter, and the other is a collection of attributeset,attributeset that can handle a set of XML tags. Using the ta.getxxx method, we can get the value of the property from the XML file and then set the values to the Control. finally, with Layoutparams to set the width height of the control, set the width high, call the AddView method, add the Control.</p></p><pre class="prettyprint"><code class=" hljs avrasm">Public Mytoolbar (context context, attributeset attrs) {super (context, attrs)<span class="hljs-comment"><span class="hljs-comment">;</span></span>TypedArray TA = context<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Obtainstyledattributes</span></span>(attrs, R<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Styleable</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. ToolBar</span></span>)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Lefttextcolor = Ta<span class="hljs-preprocessor"><span class="hljs-preprocessor">. GetColor</span></span>(R<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Styleable</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. ToolBar</span></span>_lefttextcolor,<span class="hljs-number"><span class="hljs-number">0</span></span>)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Leftbackground = Ta<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Getdrawable</span></span>(R<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Styleable</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. ToolBar</span></span>_leftbackground)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Lefttext = Ta<span class="hljs-preprocessor"><span class="hljs-preprocessor">. getString</span></span>(R<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Styleable</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. ToolBar</span></span>_lefttext)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Righttextcolor = Ta<span class="hljs-preprocessor"><span class="hljs-preprocessor">. GetColor</span></span>(R<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Styleable</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. ToolBar</span></span>_righttextcolor,<span class="hljs-number"><span class="hljs-number">0</span></span>)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Rightbackground = Ta<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Getdrawable</span></span>(R<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Styleable</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. ToolBar</span></span>_rightbackground)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Righttext = Ta<span class="hljs-preprocessor"><span class="hljs-preprocessor">. getString</span></span>(R<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Styleable</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. ToolBar</span></span>_righttext)<span class="hljs-comment"><span class="hljs-comment">;</span></span>TitleText = Ta<span class="hljs-preprocessor"><span class="hljs-preprocessor">. getString</span></span>(R<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Styleable</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. ToolBar</span></span>_title)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Titletextcolor = Ta<span class="hljs-preprocessor"><span class="hljs-preprocessor">. GetColor</span></span>(R<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Styleable</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. ToolBar</span></span>_titletextcolor,<span class="hljs-number"><span class="hljs-number">0</span></span>)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Titletextsize = Ta<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Getdimension</span></span>(R<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Styleable</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. ToolBar</span></span>_titletextsize,<span class="hljs-number"><span class="hljs-number">0</span></span>)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Ta to be recycled TA<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Recycle</span></span>()<span class="hljs-comment"><span class="hljs-comment">;</span></span>leftbtn = new Button (context)<span class="hljs-comment"><span class="hljs-comment">;</span></span>rightbtn = new Button (context)<span class="hljs-comment"><span class="hljs-comment">;</span></span>title = new TextView (context)<span class="hljs-comment"><span class="hljs-comment">;</span></span> <span class="hljs-comment"><span class="hljs-comment">/** * Set properties *</span> /</span>Leftbtn<span class="hljs-preprocessor"><span class="hljs-preprocessor">. SetText</span></span>(lefttext)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Leftbtn<span class="hljs-preprocessor"><span class="hljs-preprocessor">. SetTextColor</span></span>(lefttextcolor)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Leftbtn<span class="hljs-preprocessor"><span class="hljs-preprocessor">. SetBackground</span></span>(leftbackground)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Rightbtn<span class="hljs-preprocessor"><span class="hljs-preprocessor">. SetText</span></span>(righttext)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Rightbtn<span class="hljs-preprocessor"><span class="hljs-preprocessor">. SetTextColor</span></span>(righttextcolor)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Rightbtn<span class="hljs-preprocessor"><span class="hljs-preprocessor">. SetBackground</span></span>(rightbackground)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Title<span class="hljs-preprocessor"><span class="hljs-preprocessor">. SetText</span></span>(titletext)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Title<span class="hljs-preprocessor"><span class="hljs-preprocessor">. SetTextColor</span></span>(titletextcolor)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Title<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Settextsize</span></span>(titletextsize)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Title<span class="hljs-preprocessor"><span class="hljs-preprocessor">. Setgravity</span></span>(Gravity<span class="hljs-preprocessor"><span class="hljs-preprocessor">. CENTER</span></span>)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Sets the overall background color setbackgroundcolor (<span class="hljs-number"><span class="hljs-number">0x7cfc0055</span></span>)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Leftparams = new Layoutparams (android<span class="hljs-preprocessor"><span class="hljs-preprocessor">. View</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. ViewGroup</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. Layoutparams</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. WRAP</span></span>_content, Android<span class="hljs-preprocessor"><span class="hljs-preprocessor">. View</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. ViewGroup</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. Layoutparams</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. WRAP</span></span>_content)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Leftparams<span class="hljs-preprocessor"><span class="hljs-preprocessor">. AddRule</span></span>(relativelayout<span class="hljs-preprocessor"><span class="hljs-preprocessor">. ALIGN</span></span>_parent_left, TRUE)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Add Control AddView (leftbtn, Leftparams)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Rightparams = new Layoutparams (android<span class="hljs-preprocessor"><span class="hljs-preprocessor">. View</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. ViewGroup</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. Layoutparams</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. WRAP</span></span>_content, Android<span class="hljs-preprocessor"><span class="hljs-preprocessor">. View</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. ViewGroup</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. Layoutparams</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. WRAP</span></span>_content)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Rightparams<span class="hljs-preprocessor"><span class="hljs-preprocessor">. AddRule</span></span>(relativelayout<span class="hljs-preprocessor"><span class="hljs-preprocessor">. ALIGN</span></span>_parent_right, TRUE)<span class="hljs-comment"><span class="hljs-comment">;</span></span>AddView (rightbtn, Rightparams)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Titleparams = new Layoutparams (android<span class="hljs-preprocessor"><span class="hljs-preprocessor">. View</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. ViewGroup</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. Layoutparams</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. WRAP</span></span>_content, Android<span class="hljs-preprocessor"><span class="hljs-preprocessor">. View</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. ViewGroup</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. Layoutparams</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. MATCH</span></span>_parent)<span class="hljs-comment"><span class="hljs-comment">;</span></span>Titleparams<span class="hljs-preprocessor"><span class="hljs-preprocessor">. AddRule</span></span>(relativelayout<span class="hljs-preprocessor"><span class="hljs-preprocessor">. CENTER</span></span>_in_parent, TRUE)<span class="hljs-comment"><span class="hljs-comment">;</span></span>AddView (title, Titleparams)<span class="hljs-comment"><span class="hljs-comment">;</span></span>}</code></pre><p><p><strong>Step three: Referencing the controls we define</strong><br>After customizing the controls, we can use the custom controls to reference our custom controls in the main Layout's XML file. The first three properties of a custom control are all starting with android: this means that the properties are all system, and the subsequent properties start with custombar, indicating that the properties are all custom, in order to be able to use the custom custombar, We need to add a sentence to the Relativelayout:</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs avrasm"><span class="hljs-label">xmlns:</span>custombar=<span class="hljs-string">"http://schemas.android.com/apk/res/com.example.mytoolbar"</span></code></pre></pre><p><p>Note that the following com.example.mytoolbar is the package name that you Applied. If you are not using eclipse but Android studio, this line is not so troublesome, just write:</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs avrasm"><span class="hljs-label">xmlns:</span>custombar=<span class="hljs-string">"http://schemas.android.com/apk/res-auto"</span></code></pre></pre><p><p>Our custom properties are the properties we declare in Atts.xml to be set.</p></p><pre class="prettyprint"><code class=" hljs avrasm"><relativelayout xmlns:android=<span class="hljs-string"><span class="hljs-string">"http://schemas.android.com/apk/res/android"</span></span>Xmlns:custombar=<span class="hljs-string"><span class="hljs-string">"http://schemas.android.com/apk/res/com.example.mytoolbar"</span></span>xmlns:tools=<span class="hljs-string"><span class="hljs-string">"http://schemas.android.com/tools"</span></span>Android:layout_width=<span class="hljs-string"><span class="hljs-string">"match_parent"</span></span>android:layout_height=<span class="hljs-string"><span class="hljs-string">"match_parent"</span></span>> <<span class="hljs-keyword"><span class="hljs-keyword">com</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. Example</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. Mytoolbar</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. Mytoolbar</span></span>Android:id=<span class="hljs-string"><span class="hljs-string">"@+id/mytoolbar"</span></span>Android:layout_width=<span class="hljs-string"><span class="hljs-string">"match_parent"</span></span>android:layout_height=<span class="hljs-string"><span class="hljs-string">"48dp"</span></span>Custombar:leftbackground=<span class="hljs-string"><span class="hljs-string">"@android: color/holo_blue_light"</span></span>custombar:lefttext=<span class="hljs-string"><span class="hljs-string">"back"</span></span>Custombar:lefttextcolor=<span class="hljs-string"><span class="hljs-string">"@android: color/black"</span></span>Custombar:rightbackground=<span class="hljs-string"><span class="hljs-string">"@android: color/holo_blue_light"</span></span>custombar:righttext=<span class="hljs-string"><span class="hljs-string">"more"</span></span>Custombar:righttextcolor=<span class="hljs-string"><span class="hljs-string">"@android: color/black"</span></span>custombar:title=<span class="hljs-string"><span class="hljs-string">"title bar"</span></span>Custombar:titletextcolor=<span class="hljs-string"><span class="hljs-string">"@android: color/black"</span></span>Custombar:titletextsize=<span class="hljs-string"><span class="hljs-string">"18sp"</span></span>> </<span class="hljs-keyword"><span class="hljs-keyword">com</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. Example</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. Mytoolbar</span></span><span class="hljs-preprocessor"><span class="hljs-preprocessor">. Mytoolbar</span></span>></RelativeLayout></code></pre><p><p>After you've done the work, run your project and you'll see the picture we gave at the beginning of the Article.</p></p><p><p><strong>Fourth Step: add an event to a custom control</strong></p></p><p><p>There seems to be something less, yes, our controls don't have a click Event. To set a click event for an event, you first declare an event interface in the custom control and declare an instance of the Interface:</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs java"><span class="hljs-keyword">private</span> OnToolBarClickListener listener; <span class="hljs-keyword">public</span><span class="hljs-class"><span class="hljs-keyword">interface</span> <span class="hljs-title">OnToolBarClickListener</span> {</span> <span class="hljs-javadoc">/** * 左边按钮点击事件 */</span> <span class="hljs-keyword">public</span><span class="hljs-keyword">void</span><span class="hljs-title">leftClick</span>(); <span class="hljs-javadoc">/** * 右边按钮点击事件 */</span> <span class="hljs-keyword">public</span><span class="hljs-keyword">void</span><span class="hljs-title">rightClick</span>(); }</code></pre></pre><p><p>Then exposes a method to the other class call, the parameter of this method is this interface:</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs cs"> <span class="hljs-keyword">public</span><span class="hljs-keyword">void</span><span class="hljs-title">setOnToolBarClickListener</span>(OnToolBarClickListener listener) { <span class="hljs-keyword">this</span>.listener = listener; }</code></pre></pre><p><p>Finally in the left and right two button click event in the interface to call the method can, Smart crossing guess what is this mode?</p></p><pre class="prettyprint"><pre class="prettyprint"><code class=" hljs java"> leftBtn.setOnClickListener(<span class="hljs-keyword">new</span> OnClickListener() { <span class="hljs-annotation">@Override</span> <span class="hljs-keyword">public</span><span class="hljs-keyword">void</span><span class="hljs-title">onClick</span>(View v) { listener.leftClick(); } }); rightBtn.setOnClickListener(<span class="hljs-keyword">new</span> OnClickListener() { <span class="hljs-annotation">@Override</span> <span class="hljs-keyword">public</span><span class="hljs-keyword">void</span><span class="hljs-title">onClick</span>(View v) { listener.rightClick(); } });</code></pre></pre><p><p>Method is written, we call in Mainactivity to See:</p></p><pre class="prettyprint"><code class=" hljs java"><span class="hljs-keyword"><span class="hljs-keyword"></span> public</span> <span class="hljs-class"><span class="hljs-class"> <span class="hljs-keyword">class</span> <span class="hljs-title">mainactivity</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Activity</span> {</span></span> <span class="hljs-keyword"><span class="hljs-keyword">Private</span></span>Mytoolbar toolBar;<span class="hljs-annotation"><span class="hljs-annotation">@Override</span></span> <span class="hljs-keyword"><span class="hljs-keyword">protected</span></span> <span class="hljs-keyword"><span class="hljs-keyword">void</span></span> <span class="hljs-title"><span class="hljs-title">onCreate</span></span>(Bundle Savedinstancestate) {<span class="hljs-keyword"><span class="hljs-keyword">Super</span></span>. onCreate (savedinstancestate); Setcontentview (r.layout.activity_main); Getactionbar (). Hide ();<span class="hljs-keyword"><span class="hljs-keyword"></span> this</span>. ToolBar = (mytoolbar)<span class="hljs-keyword"><span class="hljs-keyword"></span> this</span>. Findviewbyid (r.id.mytoolbar); Toolbar.setontoolbarclicklistener (<span class="hljs-keyword"><span class="hljs-keyword">New</span></span>Ontoolbarclicklistener () {<span class="hljs-annotation"><span class="hljs-annotation">@Override</span></span> <span class="hljs-keyword"><span class="hljs-keyword"></span> public</span> <span class="hljs-keyword"><span class="hljs-keyword">void</span></span> <span class="hljs-title"><span class="hljs-title">RightClick</span></span>() {toast.maketext (mainactivity.<span class="hljs-keyword"><span class="hljs-keyword"></span> this</span>,<span class="hljs-string"><span class="hljs-string">"right click"</span></span>, toast.length_long). show (); }<span class="hljs-annotation"><span class="hljs-annotation">@Override</span></span> <span class="hljs-keyword"><span class="hljs-keyword"></span> public</span> <span class="hljs-keyword"><span class="hljs-keyword">void</span></span> <span class="hljs-title"><span class="hljs-title">Leftclick</span></span>() {toast.maketext (mainactivity.<span class="hljs-keyword"><span class="hljs-keyword"></span> this</span>,<span class="hljs-string"><span class="hljs-string">"left click"</span></span>, toast.length_long). show (); } }); }}</code></pre><p><p>This piece of code is believed to be able to read:<br>Let's see it directly:</p></p><p><p></p></p><p><p>About the Android custom UI template to introduce to you here, have questions please leave a message. Complete code download for this Project.</p></p> <p style="font-size:12px;"><p style="font-size:12px;">Copyright Notice: This article for Bo Master original article, without Bo Master permission not Reproduced. If there is a wrong place, I would appreciate it if I could criticize it.</p></p> <p><p>Android Custom UI Template graphic</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service