[Android Development Content Update category app] Third, the layout of the basic functions of the project

Source: Internet
Author: User

app Bao's: Http://android.myapp.com/myapp/detail.htm?apkName=com.jov.laughterother markets such as wood ants, the Android Market, and Sohu also haveNote: The code will be provided at the end of the article 1. Environment various Android environment articles have been many, in fact, do not need anything, the official has an Eclipse and SDK integration package, downloaded and then can run. Of course, if you say you can't turn the wall, you can tell me ... Don't say much, let's assume you've got the environment


Build your Android project.

We all know that I do not like to do the same thing two times, OK, I opened a project called the German team (bar, more often go to the two) although it is a different name, but I will make it with funny bar (after the tutorial finished, then put this pit fill), Good, my project:





Before we start, let us have an address:


http://jgilfelt.github.io/android-actionbarstylegenerator/#name =example&compat=appcompat&theme=light &actionbarstyle=solid&texture=0&hairline=0&neutralPressed=0&backColor=fff%2C100& secondarycolor=fff%2c100&tabcolor=f80%2c100&tertiarycolor=fff%2c100&accentcolor=fff%2c100& cabbackcolor=fff%2c100&cabhighlightcolor=fff%2c100


Yes, the inside is Actionbar design, related content I also do not introduce more, choose your style, click the Downloadzip button, download the package, replace the project. In addition, the file to remember changes, such as styles_example.xml (values and VALUES-V14), as well as mainfanst inside to modify your own style, to see the effect: (Icon What, paste the copy)



OK, do some testing first, open our mainactivity.


Package Com.jov.germany;import Java.io.bufferedreader;import Java.io.ioexception;import java.io.InputStream;import Java.io.inputstreamreader;import Java.net.httpurlconnection;import Java.net.malformedurlexception;import Java.net.url;import Android.os.bundle;import Android.support.v7.app.actionbaractivity;public class MainActivity Extends Actionbaractivity {@Overrideprotected void onCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (R.layout.activity_main); Testresource ();} private void Testresource () {New Thread (new Runnable () {@Overridepublic void run () {getcontentfromnetwork ();}}). Start ();} Private Boolean getcontentfromnetwork () {String path = "Http://tie163.qiniudn.com/record.txt"; URL url; String str = ""; try {url = new URL (path); HttpURLConnection conn = (httpurlconnection) url.openconnection (); Conn.setreadtimeout (6 *); if ( Conn.getresponsecode () = = () {InputStream instream = Conn.getinputstream (); str = readcontent (instream); System.out.println ("TeSt result= "+str);} Conn.disconnect (); return true;} catch (Malformedurlexception e) {e.printstacktrace ();} catch (IOException e) {e.printstacktrace ();} return false;} Private String readcontent (InputStream instream) {StringBuilder resultdata = new StringBuilder (""); try { InputStreamReader ISR = new InputStreamReader (instream); BufferedReader buffer = new BufferedReader (ISR); String inputline = Null;while ((inputline = Buffer.readline ()) = null) {resultdata.append (inputline);} Buffer.close (); Isr.close ();} catch (IOException e) {e.printstacktrace ();} return resultdata.tostring ();}}


Finally, add the following permissions to the Mainfast.xml


  <uses-permission android:name= "Android.permission.INTERNET"/>    <uses-permission android:name= " Android.permission.ACCESS_NETWORK_STATE "/>


Test to see if we have access to our network resources:




Did you succeed in it?

OK, let's go.


2, layout

We use Tabhost as the main menu, say not much, look at the code:


Activity_main.xml

<tabhost xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http://schemas.android.com/    Tools "Android:id=" @android: Id/tabhost "android:layout_width=" match_parent "android:layout_height=" Match_parent " Android:layout_alignparentleft= "true" android:layout_centervertical= "true" > <linearlayout android:l Ayout_width= "Match_parent" android:layout_height= "match_parent" android:orientation= "vertical" > & Lt Tabwidget android:id= "@android: Id/tabs" android:layout_width= "Match_parent" android:layou t_height= "Wrap_content" > </TabWidget> <framelayout android:id= "@android: I            D/tabcontent "android:layout_width=" match_parent "android:layout_height=" Match_parent ">                <fragment android:id= "@+id/image_tab" android:name= "Com.jov.germany.frame.ImageFrame" Android:layout_width= "Match_parent" android:layout_height= "Match_parent"/> <fragment and Roid:id= "@+id/text_tab" android:name= "Com.jov.germany.frame.TextFrame" android:layout_width= "Match_parent" android:layout_height= "match_parent"/> <fragment android:id = "@+id/both_tab" android:name= "Com.jov.germany.frame.BothFrame" android:layout_width= "Match_ Parent "android:layout_height=" match_parent "/> </FrameLayout> </LinearLayout>< /tabhost>

Which fragment the name of the class, and so will say,

OK, open mainactivity

Let's revise it again:


Package Com.jov.germany;import Android.os.bundle;import Android.support.v7.app.actionbaractivity;import Android.widget.tabhost;public class Mainactivity extends Actionbaractivity {private Tabhost tabhost;@ overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main); InitTab ();} private void InitTab () {tabhost = (tabhost) Findviewbyid (Android. R.id.tabhost); Tabhost.setup ();//Tabhost.setbackgroundresource (R.DRAWABLE.TOPBAR_BG); Tabhost.addtab ( Tabhost.newtabspec ("Imagetab"). Setindicator ("Picture"). SetContent (R.id.image_tab)); Tabhost.addtab ( Tabhost.newtabspec ("Texttab"). Setindicator ("Daily"). SetContent (R.id.text_tab)); Tabhost.addtab (Tabhost.newtabspec ( "Bothtab"). Setindicator ("Close Set"). SetContent (R.id.both_tab)); Tabhost.setcurrenttab (0);}}

below to build our frame, the new Imageframe.java, Textframe.java, Bothframe.java inside the content basically similar, the following gives an example:

Imageframe.java

Package Com.jov.germany.frame;import Android.annotation.suppresslint;import Android.app.fragment;import Android.os.bundle;import Android.view.layoutinflater;import Android.view.view;import Android.view.ViewGroup; Import COM.JOV.GERMANY.R; @SuppressLint ("Newapi") public class ImageFrame extends fragment{@Override public      View Oncreateview (Layoutinflater inflater, ViewGroup container,              Bundle savedinstancestate) {          return Inflater.inflate (R.layout.image_frame, container, false);      }  }

Ok we do not have the corresponding layout, to aImage_frame.xml


<?xml version= "1.0" encoding= "Utf-8"? ><relativelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" match_parent "    android:layout_height=" match_parent ">    </ Relativelayout>


Look at the effect:




The other two are the same, oh, we build it, good, first here, our framework has been, and so on the inside stuffed things.


For the time being here first ...


Code click here

[Android Development Content Update category app] Third, the layout of the basic functions of the project

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.