我正在尝试使用Android 3.1中的NumberPicker小部件.我认为它现在是标准小部件,是公共API的一部分,而不再是内部小部件.但是,它不起作用.我可以在其中看到带有"0"的textEdit,但是没有按钮,我无法滚动它,也无法用键盘输入新的数字.
这是我用于测试的xml:
<NumberPicker
android:id="@+id/numberPicker1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
通过说不起作用我的意思是:它没有显示箭头(见截图),并且在模拟器上键盘没有显示.它在一个真实的设备上,但我不能输入文本,我只能删除它.
有什么建议?当有标准的小部件时,我真的很想写自己的小部件.
我需要一个网页,其中显示了一个固定的网络内容width和height.我将webview放在高度为200px的xml文件中,但在加载该页面时,它直接重定向到默认的浏览器视图.按下手机中的后退按钮,它会重定向到原始页面,然后webview不显示任何内容.
在我的xml文件中
<WebView android:layout_width="fill_parent" android:layout_height="200px" android:id="@+id/wvbrowser" />
Run Code Online (Sandbox Code Playgroud)
在代码中
WebView wvbrowser;
wvbrowser=(WebView)findViewById(R.id.wvbrowser);
wvbrowser.loadUrl("http://www.orkut.com");
Run Code Online (Sandbox Code Playgroud)
那么告诉我哪里错了?以及如何以FIXED大小显示WebView?
我使用ArrayAdapter实现了ListView.每个listItem(行)都包含EditText.
当我尝试编辑EditText的文本时,我无法做到这一点,因为每当键盘出现时调用getView()方法并且我无法编辑文本.
任何人都可以帮我解决这个问题.
提前致谢
我想在我的按钮被按下时打印一些东西(而不是在它被释放之后)。目前我有这个,但它只能工作一次......
button.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if(event.getAction() == MotionEvent.ACTION_DOWN) {
System.out.println("pressed");
return true;
}
return false;
}
});
Run Code Online (Sandbox Code Playgroud) 我在Android应用程序中有一个EditText视图.我的EditText没有将整数值作为输入,但它正在采用所有其他值.以下是我的EditText视图.
<EditText
android:id="@+id/txtSearchItems"
android:layout_width="75dp"
android:layout_height="wrap_content"
android:visibility="visible"
android:hint="Search"
android:textSize="14dp"
android:layout_alignParentLeft="true"
android:layout_marginTop="2dp"
android:layout_centerHorizontal="true">
</EditText>
Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个自定义天文钟,这是我的代码,这是完美的问题是我想要有内阴影
公共类 CustomChronometer 扩展 Chronometer {
private boolean start = false;
private long startTime, elapsedTime;
private float angle = 0f;
private Paint paint, p;
private RectF r;
public CustomChronometer(Context context, AttributeSet attrs) {
super(context, attrs);
paint = new Paint();
paint.setColor(Color.parseColor("#0897ef"));
paint.setStrokeWidth(25);
paint.setStyle(Paint.Style.STROKE);
paint.setAntiAlias(true);
// paint.setStrokeCap(Cap.ROUND);
}
@SuppressLint("DrawAllocation")
@Override
protected void onLayout(boolean changed, int left, int top, int right,
int bottom) {
super.onLayout(changed, left, top, right, bottom);
r = new RectF(left + 30, top + 30, right - 30, bottom - …Run Code Online (Sandbox Code Playgroud) 据我了解,android 小部件需要 RemoteViews,而不是 View,就像活动一样。
我的问题:有什么办法可以完全避免xml,用java代码构建整个布局?
替代问题:我可以以某种方式检索视图,就像我会使用的那样findViewById(int)吗?例如:LinearLayout linearLayout=(LinearLayout)findViewById(R.id.xxx);这样我就可以访问基本布局,并按照我想要的方式进行操作。
谢谢!
我试图在 android 应用程序 WIDGET xml 中的所有 TextViews 下方添加一条水平线,但我有一个问题,由于某种原因,这不起作用。
编辑:这是我在应用程序中使用的小部件的完整 xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/liner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="vertical" >
<TextView
android:id="@+id/da"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/sv"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<View
android:layout_width="fill_parent"
android:layout_height="2dip"
android:background="#B3B2B0"
android:padding="10dp" />
<TextView
android:id="@+id/ti"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我试图使透明Buttons和editTexts,我使用自定义xml文件,它按预期在Android 5上工作(所有字段确实透明),但是当使用Android 4.1.1在模拟器上运行相同的应用程序时,这些字段出现黑色.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
android:background="@android:color/transparent">
<stroke android:width="3px" android:color="#FFF" />
</shape>
Run Code Online (Sandbox Code Playgroud)
如何在旧版Android操作系统上实现透明效果?
我尝试创建一个应该占据整个屏幕宽度的小部件。但它最初总是对应于android:minWidth。
当然,我可以将 android:minWidth 设置为 250 dp,但我想保持小部件可调整大小。
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="170dp"
android:minHeight="40dp"
android:updatePeriodMillis="86400000"
android:previewImage="@drawable/widget_preview"
android:initialLayout="@layout/widget_4"
android:configure="test.WidgetConfigureActivity"
android:resizeMode="horizontal"
android:widgetCategory="home_screen"
android:initialKeyguardLayout="@layout/widget_4">
</appwidget-provider>
Run Code Online (Sandbox Code Playgroud)
布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/widget_padding"
android:clickable="true"
android:focusable="true"
android:background="@color/translucent_black">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:baselineAligned="false">
<RelativeLayout
android:orientation="horizontal"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="match_parent">
<ImageButton
android:id="@+id/imageCircleButton"
android:layout_gravity="center_vertical"
android:layout_width="52dp"
android:layout_height="52dp"
android:scaleType="fitXY"
android:src="@drawable/widget_circle_w"
android:background="@android:color/transparent"
android:layout_centerVertical="true"
android:contentDescription="@string/strLevelIndicator"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/appwidget_text_level"
android:textStyle="bold"
android:textSize="30sp"
android:layout_gravity="center_vertical"
android:textColor="#ffffff"
android:text="@string/strWidgetDefLevel"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:gravity="clip_vertical"
android:layout_weight="0.8"
android:layout_gravity="left|center_vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/appwidget_text_map" …Run Code Online (Sandbox Code Playgroud) android widget android-widget android-layout android-appwidget