我目前正在Android上制作一个简单的计算器应用程序.我试图设置代码,以便当按下数字按钮时,它会用该数字更新计算器屏幕.目前我这样做.
Button one = (Button) findViewById(R.id.oneButton);
one.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TextView output = (TextView) findViewById(R.id.output);
output.append("1");
}
});
Run Code Online (Sandbox Code Playgroud)
它可以工作,但我正在为计算器上的每个按钮编写相同的代码.你可以想象它是多余的.无论如何我能以更有效的方式编写这段代码吗?一个涉及不为每个按钮编写此方法的人?
我有一个ImageView,我想用它rounded corners.
我用这个:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@null"/>
<stroke android:width="1dp"
android:color="#ff000000"/>
<corners android:radius="62px"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
并将此代码设置为我的imageview的背景.它可以工作,但我放在它上面的src图像ImageView是走出边界而不适应新的形状.
我该如何解决这个问题?
我正在做android,寻找一种方法来做一个超级基本的http GET/POST请求.我一直收到错误:
java.lang.IllegalArgumentException: Unable to create converter for class java.lang.String
Run Code Online (Sandbox Code Playgroud)
网络服务:
public interface WebService {
@GET("/projects")
Call<String> jquery();
}
Run Code Online (Sandbox Code Playgroud)
然后在我的java中:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://jquery.org")
// .addConverterFactory(GsonConverterFactory.create())
.build();
WebService service = retrofit.create(WebService.class);
Call<String> signin = service.jquery();
Toast.makeText(this, signin.toString(), Toast.LENGTH_LONG).show();
Run Code Online (Sandbox Code Playgroud)
我实际上只是尝试使用GET请求查询jquery.org/projects并返回它响应的String.怎么了?
如果我尝试实现一个自定义转换器(我在网上找到了一些例子),它抱怨我没有实现抽象方法convert(F),这些都没有.
谢谢.
嗨我有一个布局,我用来填充我的页面,我必须在我drawable folder的布局中设置一个背景图像.
我想alpha value将图像设置为相当低的几乎使图像像水印一样.
我的xml看起来像
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="@drawable/main_background" >
Run Code Online (Sandbox Code Playgroud)
如您所见,我已为布局分配了一个ID
我想在我的创造中我可以做这样的事情吗?
View backgroundimage = (View) findViewById(R.id.background);
backgroundimage.setAlpha(80);
Run Code Online (Sandbox Code Playgroud)
这不起作用,但我怀疑它是因为我试图将背景作为View我应该把它投射为什么?
虽然我已经覆盖destroyItem(...)在PagerAdapter得到一个错误,而滑动页面ViewPager
UnsupportedOperationException未覆盖必需的方法destroyItem
Java代码
public class PropertyPagerAdapter extends PagerAdapter {
private Context _context;
private int layoutId;
private List<AddPropertyInfo> dataList;
public PropertyPagerAdapter(Context context,
int resourceId, List<AddPropertyInfo> objects) {
// TODO Auto-generated constructor stub
_context = context;
layoutId = resourceId;
dataList = objects;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return dataList.size();
}
@Override
public boolean isViewFromObject(View v, Object obj) {
// TODO Auto-generated method stub
return v == ((View) obj);
}
@Override
public …Run Code Online (Sandbox Code Playgroud) 得到以下图片视图:
<ImageView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax"
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground"/>
Run Code Online (Sandbox Code Playgroud)
如果我没有为图像视图设置位图,则Ripple工作得很好.但是一旦我设置了这样的位图,涟漪效应就消失了:
ImageView iv=((ImageView)rootView.findViewById(R.id.header));
iv.setImageBitmap(myBitmap);
Run Code Online (Sandbox Code Playgroud)
这是我的ripple.xml:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item android:id="@android:id/mask">
<shape android:shape="oval">
<solid android:color="?android:colorAccent" />
</shape>
</item>
</ripple>
Run Code Online (Sandbox Code Playgroud)
我猜这个位图隐藏了涟漪效应,我怎样才能让它可见?已经尝试过:
有任何想法吗?我见过Lollipop Contacts也是这样做的.
这个库很完美,但我有一个疑问.
当我向具有两行以上的用户发送消息时,用户无法在通知区域中看到所有消息.
但我知道ANDROID可以做到
http://developer.android.com/guide/topics/ui/notifiers/notifications.html#ApplyStyle.如何通知来自parse.com?
查看图像以解释我的问题
我使用以下代码来获取android中当前运行的活动名称.
ActivityManager am = (ActivityManager) aContext
.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> alltasks = am
.getRunningTasks(1);
ComponentName componentInfo = alltasks.get(0).topActivity;
componentInfo.getClassName();
System.out.println("Current:"+componentInfo.getClassName());
Run Code Online (Sandbox Code Playgroud)
这在android下面的所有版本中运行良好5.0.但在Android 5.0中,它总是返回启动器活动.
请任何一个帮助,因为我想在所有Android版本中运行应用程序.
android ×10
java ×2
background ×1
bitmap ×1
http ×1
imageview ×1
optionmenu ×1
recording ×1
retrofit2 ×1
ripple ×1