標題:
IconText
[打印本頁]
作者:
ray
時間:
2012-11-5 18:41
標題:
IconText
PICPICPICPICPICPICPICPICPICPICPICPICPICPICPICPICPICPICPICPIC
作者:
ray
時間:
2012-11-5 19:16
package com.ray.widget;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.AttributeSet;
import android.widget.TextView;
public class IconText extends TextView
{
private int resourceId = 0;
private Bitmap bitmap;
public IconText(Context context, AttributeSet attrs)
{
super(context, attrs);
resourceId = attrs.getAttributeResourceValue(null,"iconSrc",0);
if(resourceId > 0)
bitmap = BitmapFactory.decodeResource(this.getResources(), resourceId);
else
throw new RuntimeException("必須設定iconSrc屬性!");
}
}
複製代碼
作者:
ray
時間:
2012-11-5 19:50
protected void onDraw(Canvas canvas)
{
Rect src = new Rect();
Rect target = new Rect();
src.top = 0;
src.left = 0;
src.bottom = bitmap.getHeight();
src.right = bitmap.getWidth();
target.left = 0;
target.top = (int)(this.getMeasuredHeight()-this.getTextSize())/2+1;
}
複製代碼
作者:
ray
時間:
2012-11-5 19:58
target.left = 0;
target.top = (int)(this.getMeasuredHeight()-this.getTextSize())/2+1;
target.bottom = (int)(target.top + this.getTextSize());
target.right = (int)(this.getTextSize()*bitmap.getWidth()/bitmap.getHeight());
複製代碼
作者:
ray
時間:
2012-11-5 20:18
<com.ray.widget.IconText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="30px"
iconSrc="@drawable/login"
android:text="@string/login_lbl"
/>
複製代碼
作者:
ray
時間:
2012-11-5 21:07
本帖最後由 ray 於 2012-11-5 21:09 編輯
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.ray.widget.IconText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="30px"
iconSrc="@drawable/login"
android:text="@string/login_lbl" />
<com.ray.widget.LabelEdit
android:id="@+id/account"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
labelText="@string/account_lbl"
fontSize="20"
labelPosition="left"
/>
<com.ray.widget.LabelEdit
android:id="@+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:password="true"
labelText="@string/password_lbl"
fontSize="20"
labelPosition="left"
/>
<Button
android:id="@+id/loginBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/sure_lbl"
/>
</LinearLayout>
複製代碼
作者:
ray
時間:
2012-11-5 21:07
<resources>
<string name="app_name">MeSelfUI</string>
<string name="account_lbl">帳號:</string>
<string name="password_lbl">密碼:</string>
<string name="sure_lbl">確定</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>
<string name="login_lbl">請輸入帳號密碼</string>
</resources>
複製代碼
作者:
ray
時間:
2012-11-5 21:12
public String getText()
{
return editText.getText().toString();
}
複製代碼
作者:
ray
時間:
2012-11-5 21:16
package com.ray;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity implements OnClickListener{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
((Button)this.findViewById(R.id.loginBtn)).setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
複製代碼
作者:
ray
時間:
2012-11-5 21:21
本帖最後由 ray 於 2012-11-5 21:24 編輯
package com.ray;
import com.ray.widget.LabelEdit;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
((Button)this.findViewById(R.id.loginBtn)).setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void onClick(View v) {
// TODO Auto-generated method stub
String account = ((LabelEdit)this.findViewById(R.id.account)).getText();
String password = ((LabelEdit)this.findViewById(R.id.password)).getText();
Toast.makeText(this,"account="+account+"/password="+password,Toast.LENGTH_SHORT).show();
}
}
複製代碼
作者:
ray
時間:
2012-11-7 19:01
public void onClick(View v)
{
// TODO Auto-generated method stub
String account = ((LabelEdit)this.findViewById(R.id.account)).getText();
String password = ((LabelEdit)this.findViewById(R.id.password)).getText();
if(account.equals(password))
{
Intent intent = new Intent(MainActivity.this,SubActivity.class);
startActivity(intent);
}
else
Toast.makeText(this,"error",Toast.LENGTH_SHORT).show();
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2