我正在使用这个教程:
http://android-developers.blogspot.com/2011/04/customizing-action-bar.html
我设置了这样的下拉列表主题
<!-- style the list navigation -->
<style name="MyDropDownNav" parent="android:style/Widget.Holo.Light.Spinner.DropDown.ActionBar">
<item name="android:textColor">#ffffff</item>
</style>
Run Code Online (Sandbox Code Playgroud)
现在按下微调器使它显示在屏幕中心而不是下拉.有没有人碰到这个?我正在使用他们在示例中所说的内容.即使我删除文本颜色并且只有基于父级的空样式,微调器也会出现在屏幕中间.有人发现了解决这个问题的方法吗?
编辑:我忘了提及的另一件事,风格甚至没有将文本更新为白色.
我只知道通过id获取视图的一种方法:
getViewById(R.drawable.imageButton)
Run Code Online (Sandbox Code Playgroud)
但是,如果我没有活动(开发一个小部件应用程序),我该如何获得这个imageButton?
我能够得到一个背景.我想这足以获得视图 - 上下文只包含一个小部件不是吗?如果没有 - 那么如何获取每个小部件视图?
我有一个Web服务,根据图像id,给我一个byte []数组。我想将这些byte []转换为文件,然后将文件存储在android上,用户想要在其中保存具有相同格式的文件的对话框。
是否可以为ICS版本设置一个开关小部件,但是有一个用于预ICS的复选框?如果是这样,怎么样?
我不担心其他组件,只有开关.
我的解决方案
看到switch和checkbox都从CompoundButton继承,我就是这么做的
((CompoundButton)findViewById(R.id.swTax)).setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
calculateValues();
}
});
Run Code Online (Sandbox Code Playgroud) 我被困在一个特殊的场景中。用户从应用程序更新时间后,我需要立即更新我的小部件。我确实通过发送Intent Extras数据来尝试广播,但是没有这样做。当前,我的数据存储在AppWidgetProvider中,我需要将此数据发送到服务
公共类CountdownWidget扩展了AppWidgetProvider {// SharedPreferences userDefaults;
// update rate in milliseconds
public static final int UPDATE_RATE = 1800000; // 30 minute
public static String nameOne = "";
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
for (int appWidgetId : appWidgetIds) {
setAlarm(context, appWidgetId, -1);
}
super.onDeleted(context, appWidgetIds);
}
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Bundle extras = intent.getExtras();
nameOne = extras.getString("NAME_ONE");
Log.e("Name: ", nameOne);
super.onReceive(context, intent);
}
@Override
public void onUpdate(Context context, AppWidgetManager …Run Code Online (Sandbox Code Playgroud) 我有一个EditText数组,我想禁用每次点击它们时出现的标准键盘Android.
这些是我正在使用的零件代码:
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
for (i=0;i<dim*dim;i++){
imm.hideSoftInputFromWindow(value[i].getWindowToken(), 0);
value[i].setOnTouchListener(this);
value[i].setOnClickListener(this);
value[i].setOnFocusChangeListener(this);
}
Run Code Online (Sandbox Code Playgroud)
编辑:
我用这些代码行创建了一个新类:
import android.content.Context;
import android.util.AttributeSet;
import android.widget.EditText;
public class KeyboardControlEditText extends EditText {
private boolean mShowKeyboard = false;
public void setShowKeyboard(boolean value) {
mShowKeyboard = value;
}
// This constructor has to be overriden
public KeyboardControlEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
// Now tell the VM whether or not we are a text editor
@Override
public boolean onCheckIsTextEditor() {
return mShowKeyboard;
} …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中得到android.os.NetworkOnMainThreadException.我正试图从网址获取图像,当时我得到了这个Exception.如果我在2.2中运行应用程序它工作正常,但如果我在4.0上运行获得异常.
public static Bitmap getBitmap(String url)
{
Bitmap bitmap = null;
try
{
// replace space with url encoded character.
url = url.replace(" ", "%20");
// System.out.println("url : " + url);
URL urll = new URL(url);
InputStream in = (InputStream) urll.getContent();
bitmap = BitmapFactory.decodeStream(in);
}
catch ( MalformedURLException e )
{
e.printStackTrace();
}
catch ( IOException e )
{
e.printStackTrace();
}
if ( bitmap == null )
bitmap = BitmapFactory.decodeResource(resources, R.drawable.noimage);
return bitmap;
}
Run Code Online (Sandbox Code Playgroud)
我收到了错误
InputStream …Run Code Online (Sandbox Code Playgroud) 我在一个应用程序中工作,当我选择(自动发送按钮打开)时,该应用程序必须每5秒向服务器发送一个GPS位置.我是android的新手,所以我不知道如何制作开/关按钮,如何在按钮打开时调用每5秒发送一次数据的方法.
它必须每5秒调用一次的方法:
public void postData() throws ClientProtocolException, IOException, Exception {
String longitude="UK";
String latitude="UK";
String altitiude="UK";
String time="";
String speed="";
getCurrentLocation(); // gets the current location and update mobileLocation variables
if (mobileLocation != null) {
locManager.removeUpdates(locListener); // This needs to stop getting the location data and save the battery power.
longitude = ""+mobileLocation.getLongitude();
latitude = "" + mobileLocation.getLatitude();
altitiude = "" + mobileLocation.getAltitude();
String accuracy = "Accuracy" + mobileLocation.getAccuracy();
time = "" + mobileLocation.getTime();
speed =""+ (int)(4*mobileLocation.getSpeed());
editTextShowLocation.setText(longitude + "\n" …Run Code Online (Sandbox Code Playgroud) 是否可以在每个方向上按任意因子缩放RectF对象?在实践中,我将调整RectF的2倍大小(如果RectF为200X200,则我将其变为100x100)
我正在尝试为我的应用程序实现一个简单的集合小部件,我试图ListView在一个小部件内部显示但是ListView仍然停留在Loading ...并且从未完成加载,并且我在数据库中有数据并且列表视图仍然是坚持下去.
这是onUpdate我的AppWidgetProvider类的方法:
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
int length = appWidgetIds.length;
for (int x = 0; x < length; x++){
RemoteViews remote = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
Intent intent = new Intent(context,RViewsService.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[x]);
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
remote.setRemoteAdapter(R.id.list,intent);
remote.setEmptyView(R.id.list,R.id.empty);
remote.setTextViewText(R.id.title,Utilities.setDayOfWeek());
////////////////////////////////////////////////////////////////////////////////////////////////////////
Intent AddmateriaIntent = new Intent(context,AddMateria.class);
PendingIntent pendingItentForButtonAddMateria = PendingIntent.getActivity(context,0,AddmateriaIntent,0);
remote.setOnClickPendingIntent(R.id.add,pendingItentForButtonAddMateria);
remote.setOnClickPendingIntent(R.id.empty, pendingItentForButtonAddMateria);
appWidgetManager.updateAppWidget(appWidgetIds[x],remote);
}
super.onUpdate(context,appWidgetManager,appWidgetIds);
}
Run Code Online (Sandbox Code Playgroud)
我可以检查并且该方法onUpdate完成其工作而没有错误.这里是RemoteViewService和RemoteViewsFactory,它们也没有在logCat上显示错误.
公共类RViewsService扩展了RemoteViewsService {
@Override
public RemoteViewsFactory onGetViewFactory(Intent intent) {
return new RViewFactory(getApplicationContext(),intent); …Run Code Online (Sandbox Code Playgroud) android android-widget android-listview appwidgetprovider android-remoteview