Phonegap native Control (Android) mixed with HTML

Source: Internet
Author: User

1. Create a Cordova project with a command

Cordova coreate Hello Com.example.hello Hello

2. Open Mainactivity

In the OnCreate method, add

Setcontentview (r.layout.main_activity);

3. main_activity files are as follows:

<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Match_parent "android:layout_height=" match_parent "android:orientation=" vertical " > <relativelayout android:layout_width= "fill_parent" android:layout_height= "45dip" android:b ackground= "#25C28B" > <imagebutton android:id= "@+id/cordova_back" android:layout_width= "Wrap_content" android:layout_height= "match_parent" android:background= "#00FFFFFF" Androi d:paddingleft= "10DP" android:paddingright= "20DP" android:src= "@drawable/back_all"/> <t Extview android:id= "@+id/cordova_title" android:layout_width= "Wrap_content" android:layou t_height= "Wrap_content" android:layout_centerinparent= "true" android:text= "native Head" Android: Textcolor= "#FFFFFF" AndroidOid:textsize= "20sp"/> <button android:id= "@+id/btn_report" android:layout_width= "Wrap_ Content "android:layout_height=" Match_parent "android:layout_alignparentright=" true "Android Oid:background= "#00FFFFFF" android:paddingleft= "10DP" android:paddingright= "20DP" Android : text= "Report" android:textcolor= "#FFFFFF" android:textsize= "20sp"/> </RelativeLayout> & Lt;org.apache.cordova.engine.systemwebview android:id= "@+id/cordovawebview" android:layout_width= "Match_pare NT "android:layout_height=" Match_parent "/></linearlayout>

Systemwebview is an extended WebView

4. Re-Makewebview method and Createviews method

  @Override    protected Cordovawebview Makewebview () {        Systemwebview WebView = (systemwebview) Findviewbyid ( R.id.cordovawebview);        Cordovawebview Cordovawebview = new Cordovawebviewimpl (new Systemwebviewengine (WebView));        return cordovawebview;    }

Cordovawebview for Systemwebview controls in XML

   @Override    protected void Createviews () {        if (preferences.contains ("BackgroundColor")) {            int BackgroundColor = Preferences.getinteger ("BackgroundColor", color.black);            Background of activity:            Appview.getview (). SetBackgroundColor (backgroundcolor);        Appview.getview (). Requestfocusfromtouch ();    }

  

5.

Phonegap native Control (Android) mixed with HTML

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.