【发布时间】:2015-06-17 15:21:28
【问题描述】:
我正在尝试使用他们参考中的代码在 Android Studio 中创建一个 TextView(我已经知道我可以使用 XML,但我正在尝试学习 java)。我的代码不起作用,我不知道为什么。我看起来就像参考上的代码。我试图弄清楚如何使用 Android 参考指南在 Android Studio 中编写代码。任何使用参考指南的提示和技巧都值得赞赏。
注意:请不要让 cmets 说我需要购买 java 书,参加 java 课程等,因为我已经这样做了。
我所指的参考资料 (http://developer.android.com/reference/android/widget/TextView.html#)
//(class) Adds TextView
public class TextView extends MainActivity{
CharSequence myText = "Marsha Jackson - (555) 555-5555 - marsha.jackson@email.com - www.jkl.com";
//(method) Sets width for the textview
public void setWidth (int pixels){
int = 100;
}
//(method) Sets the height of the TextView
public void setHeight (int pixels){
int = 500;
}
//(method) Sets the size of the text
public void setTextSize (float size){
float = 40;
}
//Sets the typeface fo the font
public void setTypeface (Typeface tf) {
Typeface Arial;
}
//(method) Sets the text color
public void setTextColor (ColorStateList colors){
ColorStateList Red;
}
//(method) Sets the colors for links
public final void setLinkTextColor (int color) {
int Yellow;
}
//(method)Sets highlighted text color
public void setHighlightColor (int color){
int Green;
}
//(method) Sets text to be ellipsized
public void setEllipsize (TextUtils.TruncateAt where){
Enum END;
}
//(method) Sets text
public final void setText(CharSequence text){
myText = text;
}
//(method)Makes text selectable
public void setTextIsSelectable (boolean selectable){
}
//(method) Return the state of the textIsSelectable flag
public boolean isTextSelectable(){
return (setTextIsSelectable);
}
//(Method) Lets user select websites, phone numbers, and emails
public final void setAutoLinkMask (int mask){
public static final int all{
}
//(Field)Filters out numbers that are too short to be phone numbers
public static final Linkify.MatchFilter sPhoneNumberMatchFilter{
}
//(Field)Filters out symbols that can be in phone numbers
public static final Linkify.TransformFilter sPhoneNumberTransformFilter{
}
//(Field) Prevent text after @ sign from becoming a website link
public static final Linkify.MatchFilter sUrlMatchFilter{
}
}
}
【问题讨论】:
-
您收到了哪些错误(如果有)?
-
TextView extends MainActivity似乎不对。您通常会创建一个TextView并将其添加到活动布局中。但是现在,您的TextView实际上是MainActivity没有设置布局。
标签: java android android-studio