標題:
MeSelfUI
[打印本頁]
作者:
ray
時間:
2012-10-31 21:27
標題:
MeSelfUI
<LabelEdit
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:password="true"
labelText="@string/password_lbl"
fontSize="20"
labelPosition="left"
/>
複製代碼
作者:
ray
時間:
2012-11-2 19:02
int resourceId = attrs.getAttributeResourceValue(null, "labelText", 0);
if(resourceId == 0)
labelText = attrs.getAttributeValue(null,"labelText");
else
labelText = this.getResources().getString(resourceId);
複製代碼
作者:
ray
時間:
2012-11-2 19:18
resourceId = attrs.getAttributeResourceValue(null, "fontSize", 0);
if(resourceId == 0)
fontSize = attrs.getAttributeIntValue(null,"fontSize",14);
else
fontSize = this.getResources().getInteger(resourceId);
複製代碼
作者:
ray
時間:
2012-11-2 19:28
resourceId = attrs.getAttributeResourceValue(null, "labelPosition", 0);
if(resourceId == 0)
labelPosition = attrs.getAttributeValue(null,"labelPosition");
else
labelPosition = this.getResources().getString(resourceId);
if(labelPosition == null)
labelPosition = "left";
複製代碼
作者:
ray
時間:
2012-11-2 19:30
resourceId = attrs.getAttributeResourceValue(namespace, "password", 0);
if (resourceId == 0)
isPassword = attrs.getAttributeValue(namespace, "password");
else
isPassword = getResources().getString(resourceId);
if (isPassword == null)
isPassword = "false";
複製代碼
作者:
ray
時間:
2012-11-2 19:57
本帖最後由 ray 於 2012-11-2 20:01 編輯
textView = new TextView(context);
textView.setTextSize(fontSize);
textView.setText(labelText);
this.addView(textView);
複製代碼
作者:
ray
時間:
2012-11-2 20:07
editText = new EditText(context);
editText.setWidth(50000);
if(isPassword.equals("true"))
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
this.addView(editText);
複製代碼
作者:
ray
時間:
2012-11-2 20:36
package com.ray.widget;
import android.content.Context;
import android.text.method.PasswordTransformationMethod;
import android.util.AttributeSet;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
public class LabelEdit extends LinearLayout
{
private final String namespace = "http://schemas.android.com/apk/res/android";
private TextView textView;
private EditText editText;
private String labelText;
private int fontSize;
private String isPassword;
private String labelPosition;
public LabelEdit(Context context,AttributeSet attrs)
{
super(context,attrs);
int resourceId = attrs.getAttributeResourceValue(null, "labelText", 0);
if(resourceId == 0)
labelText = attrs.getAttributeValue(null,"labelText");
else
labelText = this.getResources().getString(resourceId);
if(labelText == null)
throw new RuntimeException("必須設定labelText屬性!");
resourceId = attrs.getAttributeResourceValue(null, "fontSize", 0);
if(resourceId == 0)
fontSize = attrs.getAttributeIntValue(null,"fontSize",14);
else
fontSize = this.getResources().getInteger(resourceId);
resourceId = attrs.getAttributeResourceValue(null, "labelPosition", 0);
if(resourceId == 0)
labelPosition = attrs.getAttributeValue(null,"labelPosition");
else
labelPosition = this.getResources().getString(resourceId);
if(labelPosition == null)
labelPosition = "left";
resourceId = attrs.getAttributeResourceValue(namespace, "password", 0);
if (resourceId == 0)
isPassword = attrs.getAttributeValue(namespace, "password");
else
isPassword = getResources().getString(resourceId);
if (isPassword == null)
isPassword = "false";
if(labelPosition.equals("top"))
this.setOrientation(VERTICAL);
else
this.setOrientation(HORIZONTAL);
textView = new TextView(context);
textView.setTextSize(fontSize);
textView.setText(labelText);
this.addView(textView);
editText = new EditText(context);
editText.setWidth(50000);
if(isPassword.equals("true"))
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
this.addView(editText);
}
}
複製代碼
作者:
ray
時間:
2012-11-2 20:37
<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" >
<com.ray.widget.LabelEdit
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:password="true"
labelText="@string/password_lbl"
fontSize="20"
labelPosition="left"
/>
</LinearLayout>
複製代碼
作者:
ray
時間:
2012-11-2 20:37
<resources>
<string name="app_name">MeSelfUI</string>
<string name="password_lbl">密碼:</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>
</resources>
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2