[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. Sohu has it all.Note: The code will be provided at the end of the article 1. Environment various Android environment articles have been very much, in fact, there is no need, the official has an Eclipse and SDK integration package, downloaded and can be executed. Of course. Suppose you say you can't turn the wall. Can you tell me ...? Don't say much, let's assume you've got the environment


Build your Android project.

As we all know, I do not like to do the same thing two times, OK, I opened a project called the German team bar. Two more often than not, though it's a different name, I'm going to make it look like a funny one (after the tutorial is finished, fill in the pit). 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, the related content I also do not introduce more, choose your style. Click on the Downloadzipbutton to download the package and replace it with the project. In addition the time to replace. Remember to change the file. For example Styles_example.xml (values and VALUES-V14), as well as mainfanst inside changes to your own style, to see the effect: (Icon What, paste in copy)



OK, let's 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 in 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. We continue to


2, layout

Let's use Tabhost as the basic menu. Words don't say 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>

Among the classes in fragment's name, and so on, will say,

Ok. Open mainactivity

Let's change it once 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);}}

To come down to build our frame, the new Imageframe.java, Textframe.java, Bothframe.java inside the content almost identical, the following to a sample:

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 them, good, first here. We've got the frame, and we're going to have to stuff it in there.


Come here on a temporary basis.


Code click here

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

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.