当前位置: 编程技术>移动开发
本页文章导读:
▪转:AndEngine中的字体加载及使用 转:AndEngine中的字体加载及应用
AndEngine中的字体加载及应用
AndEngine中的字体加载及应用
public void onLoadResources() {
this.mTexture1 = new Texture(256, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
FontFact.........
▪ 仿照天天动听的seekbar 模仿天天动听的seekbar
// main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_heig.........
▪ Spinner 跟Menu菜单展示关于退出的用法 Spinner 和Menu菜单展示关于退出的用法
这节接着上一节“自定义登陆弹出框”,我们编写一个spinner,和点击Menu菜单查看关于与退出的操作
效果如图:
静态效果 选择spinner:
点击手机上.........
[1]转:AndEngine中的字体加载及使用
来源: 互联网 发布时间: 2014-02-18
转:AndEngine中的字体加载及应用
AndEngine中的字体加载及应用
AndEngine中的字体加载及应用 public void onLoadResources() { this.mTexture1 = new Texture(256, 256, TextureOptions.BILINEAR_PREMULTIPLYALPHA); FontFactory.setAssetBasePath("font/"); this.mPlokFont = FontFactory.createFromAsset(this.mTexture1, this, "Plok.ttf", 30, true, Color.BLACK); this.mEngine.getTextureManager().loadTexture(this.mTexture1); this.mEngine.getFontManager().loadFonts(this.mPlokFont); } public Scene onLoadScene() { this.mEngine.registerUpdateHandler(new FPSLogger()); final Scene scene = new Scene(1); scene.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f)); scene.getTopLayer().addEntity(new Text(140, 300, this.mPlokFont, "hello!")); return scene; }
转自:http://361tg.net/read.php?17
[2] 仿照天天动听的seekbar
来源: 互联网 发布时间: 2014-02-18
模仿天天动听的seekbar
// main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <SeekBar android:id="@+id/seek" android:layout_width="fill_parent" android:layout_height="wrap_content" android:minHeight="2px" android:maxHeight="2px" android:paddingLeft="5px" android:paddingRight="5px" android:max="100" android:progress="50" android:progressDrawable="@drawable/seekbar_img" android:thumb="@drawable/thumb" android:thumbOffset="1px" android:scrollbar /> </LinearLayout> //seekbar_img.xml <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 背景图 --> <item android:id="@android:id/background" android:drawable="@drawable/seekbar_back" /> <!--全部能量图 --> <!-- <item android:id="@+android:id/SecondaryProgress" android:drawable="@drawable/back" /> --> <!-- 进和能量图 --> <item android:id="@android:id/progress" android:drawable="@drawable/seekbar_fill" /> </layer-list> // thumb.xml <?xml version="1.0" encoding="UTF-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <!-- 按下状态 --> <item android:state_pressed="true" android:drawable="@drawable/seekbar_handle" /> <!-- 普通无焦点状态 --> <item android:state_focused="false" android:state_pressed="false" android:drawable="@drawable/seekbar_handle" /> </selector>
[3] Spinner 跟Menu菜单展示关于退出的用法
来源: 互联网 发布时间: 2014-02-18
Spinner 和Menu菜单展示关于退出的用法
这节接着上一节“自定义登陆弹出框”,我们编写一个spinner,和点击Menu菜单查看关于与退出的操作
效果如图:
静态效果
选择spinner:
点击手机上的Menu按钮效果:
点击Menu关于选项:
点击退出:
提交数据弹出等待框:
代码:
package com.gk.view; import java.util.ArrayList; import java.util.List; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; import android.app.Activity; import android.app.ActivityManager; import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.Spinner; import android.widget.TextView; import android.widget.Toast; import com.gk.R; import com.gk.model.Agent; public class mainview extends Activity implements OnItemSelectedListener,OnClickListener{ private TextView mytextview; private Spinner myspinner; private String[] items ={"未完成","已完成"}; private ArrayAdapter<String> ad; private ImageButton seachbutton; private ImageView outview; private EditText expertxt; private String itemvalue=""; private List<NameValuePair> params; private ProgressDialog progressdialog; private AlertDialog comfirmDialog; private AlertDialog about; private String expername; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mainview); //setContentView(R.layout.mainview);//设置布局 //这里是登陆传递过来的对象,看不懂的话看看上一节吧,主要是用来取出登陆的用户名,显示在节目上 //Agent agent = (Agent) getIntent().getSerializableExtra("agentvalue"); Bundle bundle = getIntent().getExtras(); Agent agent = (Agent) bundle.get("agent"); //要使用spinner需要实现OnItemSelectedListener接口 mytextview =(TextView) findViewById(R.id.textviewtitle); mytextview.setText("当前用户:"+agent.getAgentname()); myspinner =(Spinner) findViewById(R.id.mySpinner); //创建适配器 ad =new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,items); ad.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); myspinner.setAdapter(ad); myspinner.setOnItemSelectedListener(this);//实现监听器 seachbutton =(ImageButton) findViewById(R.id.seachbutton); seachbutton.setOnClickListener(this); expertxt = (EditText) findViewById(R.id.txt_expert); expertxt.setText("xxxx");//这里为了测试方便,写上默认值 outview =(ImageView) findViewById(R.id.outview); outview.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder ad = new AlertDialog.Builder(mainview.this); ad.setTitle("提示"); ad.setMessage("确认退出吗?"); comfirmDialog=ad.create(); comfirmDialog.setButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //退出系统 ActivityManager activityManager=(ActivityManager) mainview.this.getSystemService(ACTIVITY_SERVICE); activityManager.restartPackage("com.gk"); } }); comfirmDialog.setButton2("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { comfirmDialog.cancel();//取消 } }); comfirmDialog.show();//显示对话框 } }); } @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { //mytextview.setText(items[position]); itemvalue =items[position]; System.out.println("selected:"+items[position]); } @Override public void onNothingSelected(AdapterView<?> parent) { } @Override //seachbutton点击事件 public void onClick(View v) { //itemvalue expername = expertxt.getText().toString(); System.out.println(itemvalue+" "+expername); //组装参数 params =new ArrayList<NameValuePair>(); String ov; progressdialog =ProgressDialog.show(mainview.this, "请等待...", "正在提交..."); params.add(new BasicNameValuePair("overflag", itemvalue)); params.add(new BasicNameValuePair("consultationexpert", expername)); seachr.sleep(100); } private seachHandler seachr =new seachHandler(); class seachHandler extends Handler{ @Override public void handleMessage(Message msg) { try{ Intent intent =new Intent(); intent.setClass(mainview.this, taskView.class); intent.putExtra("overflag", itemvalue); //将查询参数传递到下一个Activity让它进行查询 intent.putExtra("consultationexpert", expername); mainview.this.startActivity(intent); Toast.makeText(mainview.this, "提交完毕", Toast.LENGTH_SHORT).show(); }catch(Exception e){ e.printStackTrace(); }finally{ progressdialog.dismiss(); } } //设置消失的时间 public void sleep(long delayMillis){ this.removeMessages(0); sendMessageDelayed(obtainMessage(0), delayMillis); } } //Menu需要实现的两个方法 @Override public boolean onCreateOptionsMenu(Menu menu) { menu.add(0, 1, 1, "关于"); menu.add(0, 2, 2, "退出"); return super.onCreateOptionsMenu(menu); } @Override public boolean onMenuItemSelected(int featureId, MenuItem item) { LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.about, null); if(item.getItemId() == 1){ AlertDialog.Builder ad =new AlertDialog.Builder(this); ad.setTitle("关于"); ad.setView(view); about = ad.create(); about.setButton("关闭", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { about.cancel(); } }); about.show(); }else{ ActivityManager activityManager=(ActivityManager) mainview.this.getSystemService(ACTIVITY_SERVICE); activityManager.restartPackage("com.gk"); //com.gk是项目的默认包 看看你R.java的所在包就是他了 //要实现退出系统还需要在AndroidManifest.xml文件里注册一个权限 // <uses-permission android:name="android.permission.RESTART_PACKAGES"/> } return super.onMenuItemSelected(featureId, item); } }
布局文件:
about.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:text="关于的内容xxxxx"/> </LinearLayout> mainview.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/bg" android:orientation="vertical" > <ImageView android:id="@+id/outview" android:layout_width="fill_parent" android:layout_height="63dip" android:background="@drawable/title"/> <LinearLayout android:layout_width="fill_parent" android:background="@drawable/content" android:layout_height="203dip" android:gravity="center_vertical" android:orientation="vertical" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dip" android:layout_marginRight="20dip" android:gravity="left" android:text="咨询状态:" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="#78B52E" /> <Spinner android:id="@+id/mySpinner" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="0dip" android:layout_marginRight="20dip" android:layout_weight="0.26" android:autoText="false" android:capitalize="none" android:gravity="fill_horizontal" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="20dip" android:layout_marginRight="20dip" android:textColor="#78B52E" android:gravity="left" android:text="专家姓名:" android:textAppearance="?android:attr/textAppearanceMedium" /> <EditText android:id="@+id/txt_expert" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="0dip" android:layout_marginRight="20dip" android:autoText="false" android:capitalize="none" android:gravity="fill_horizontal" android:textAppearance="?android:attr/textAppearanceMedium" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="right" > <ImageButton android:id="@+id/seachbutton" android:layout_width="100dip" android:layout_height="40dip" android:layout_marginRight="20dip" android:background="@drawable/seach" android:text="查 询" /> </LinearLayout> </LinearLayout> <TextView android:id="@+id/textviewtitle" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" /> </LinearLayout>
最新技术文章: