Questions tagged «android»

Android是Google的移动操作系统,用于对数字设备(智能手机,平板电脑,汽车,电视,Wear,Glass和IoT)进行编程或开发。对于与Android相关的主题,请使用特定于Android的标签,例如android-intent,android-activity,android-adapter等。对于与开发或编程无关但与Android框架相关的问题,请使用以下链接:https:// android.stackexchange.com。

3
在Android中停止服务
在这里,我尝试了简单的服务程序。启动服务可以正常工作并生成Toast,但停止服务则不能。此简单服务的代码如下: public class MailService extends Service { @Override public IBinder onBind(Intent arg0) { // TODO Auto-generated method stub return null; } public void onCreate(){ super.onCreate(); Toast.makeText(this, "Service Started", Toast.LENGTH_SHORT).show(); } public void onDestroyed(){ Toast.makeText(this, "Service Destroyed", Toast.LENGTH_SHORT).show(); super.onDestroy(); } } 调用此服务的活动的代码如下: public class ServiceTest extends Activity{ private Button start,stop; public …
79 android  service 

7
FrameLayout边距不起作用
我的布局结构是这样的 LinearLayout FrameLayout ImageView ImageView FrameLayout TextView LinearLayout 我为FrameLayout内的两个ImageView设置了边距。但是FrameLayout的边距将被丢弃,并且始终将Image设置在左上角。如果我从FrameLayout更改为LinearLayout,则边距正常工作。如何处理呢? <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/inner1" > <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" > <ImageView android:layout_width="24px" android:layout_height="24px" android:id="@+id/favicon" android:layout_marginLeft="50px" android:layout_marginTop="50px" android:layout_marginBottom="40px" android:layout_marginRight="70px" /> <ImageView android:layout_width="52px" android:layout_height="52px" android:id="@+id/applefavicon" android:layout_marginLeft="100px" android:layout_marginTop="100px" android:layout_marginBottom="100px" android:layout_marginRight="100px" /> </FrameLayout> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/title" android:layout_marginLeft="10px" android:layout_marginTop="20px" android:textColor="#FFFFFF" …

13
如何在Android中的linearlayout周围显示阴影?
如何显示线性布局的阴影。我想要带有圆线布局周围阴影的白色圆形背景。到目前为止,我已经做到了。 <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:background="@xml/rounded_rect_shape" android:orientation="vertical" android:padding="10dp"> <-- My buttons, textviews, Imageviews go here --> </LinearLayout> 以及xml目录下的rounded_rect_shape.xml <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" > <solid android:color="#ffffff" /> <corners android:bottomLeftRadius="3dp" android:bottomRightRadius="3dp" android:topLeftRadius="3dp" android:topRightRadius="3dp" /> </shape>

9
Android-从HashMap获得价值
我试图在Android中的HashMap上进行搜索,但是出现问题: 考虑以下示例: HashMap<String, String> meMap=new HashMap<String, String>(); meMap.put("Color1","Red"); meMap.put("Color2","Blue"); meMap.put("Color3","Green"); meMap.put("Color4","White"); 现在,我想对其进行迭代并获取每种颜色的值,并希望在“ Toast”中显示。如何显示?

3
Android中String.join的替代选择?
我想用逗号作为分隔符连接一个ArrayList。我找到了这个答案,说明可以String.join在Java中使用。 但是,当我尝试使用此功能时,Android Studio出现以下错误: 无法解析方法'join(java.lang.String,java.lang.String,java.lang.String,java.lang.String)' Android Studio是否有一个好的简洁的替代方法(而不是使用for循环)?
79 java  android 

4
是在onActivityResult()之前调用onResume()吗?
这是我的应用程序的布局方式: 提示onResume()用户登录 如果用户登录,他可以继续使用应用程序 3。如果用户随时注销,我想再次提示登录 我该如何实现? 这是我的MainActivity: @Override protected void onResume(){ super.onResume(); isLoggedIn = prefs.getBoolean("isLoggedIn", false); if(!isLoggedIn){ showLoginActivity(); } } 这是我的LoginActivity: @Override protected void onPostExecute(JSONObject json) { String authorized = "200"; String unauthorized = "401"; String notfound = "404"; String status = new String(); try { // Get the messages array …

8
从iOS / Android上的网络应用调用本地日期选择器
我正在尝试使用HTML5在不同平台上运行本机Web应用程序的可能性。当前,一个<input type="date">字段仅在Android和iOS上打开标准软键盘。我想,将来移动操作系统的软键盘将包括日期选择器等,就像<select>今天调用本机选择一样。 由于未在Android或iOS上实现,而是在本机UI中实现,因此网络应用程序是否有可能调用本机日期选择器,即在单击时? 这将使我们能够停止使用jQuery mobile和YUI之类的JavaScript库。 如果我的问题仍然不清楚,请告诉我。先感谢您 :-)

5
何时注册/注销活动中创建的广播接收器?
我需要在活动的onCreate事件中创建自定义广播接收器,并且显然我需要在活动的onDestroy事件中取消注册广播接收器 为了清楚起见,这是我使用的代码的一部分 public class AnActivity extends Activity { private ResponseReceiver receiver; public class ResponseReceiver extends BroadcastReceiver { public static final String ACTION_RESP = "mypackagename.intent.action.MESSAGE_PROCESSED"; @Override public void onReceive(Context context, Intent intent) { // TODO Start a dialogue if message indicates successfully posted to server } } /** Called when the …


8
无法在Kotlin中“ findViewById”。出现错误“类型推断失败”
我尝试RecycleView按ID查找ID时遇到以下错误。 错误:- 类型推断失败:没有足够的信息来推断参数T 码: class FirstRecycleViewExample : AppCompatActivity() { val data = arrayListOf<String>() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.first_recycleview) val recycler_view = findViewById(R.id.recycler_view) as RecyclerView ///IN THIS LINE I AM GETTING THE ERROR data.add("First Data") data.add("Second Data") data.add("Third Data") data.add("Forth Data") data.add("Fifth Data") //creating our adapter val adapter = …

5
如何创建数字选择器对话框?
我希望能够创建一个对话框,允许用户从指定范围内选择一个数字。 我知道已经有现成的小部件(例如悄悄地编码的小部件和SimonVT的小部件)已经完成了,但是我很难将它们正确地集成到我的应用程序中。而且,这些主要是小部件。我想要的东西与android开发人员页面教程中的非常相似。 我还检查了NumberPicker的文档,并说要检查TimePicker和DatePicker的示例,但是它们仅显示了如何使用时间和日期选择器,而我很难理解代码的方式并尝试转换代码。时间选择器只是一个普通的数字选择器。有谁知道从哪里开始?我一直在寻找过去3个小时内没有解决方案的解决方案。

11
如何知道RecyclerView / LinearLayoutManager是滚动到顶部还是底部?
目前,我正在使用以下代码来检查是否应启用SwipeRefreshLayout。 private void laySwipeToggle() { if (mRecyclerView.getChildCount() == 0 || mRecyclerView.getChildAt(0).getTop() == 0) { mLaySwipe.setEnabled(true); } else { mLaySwipe.setEnabled(false); } } 但这是问题所在。滚动到另一个项目的视图边界时,它mRecyclerView.getChildAt(0).getTop()也会返回0。 是否有类似RecyclerView.isScrolledToBottom()或RecyclerView.isScrolledToTop()? 编辑:(mRecyclerView.getChildAt(0).getTop() == 0 && linearLayoutManager.findFirstVisibleItemPosition() == 0)有点RecyclerView.isScrolledToTop(),但是呢RecyclerView.isScrolledToBottom()?

17
如何使用“使用共享图片”共享意图在Android中共享图片?
我在该应用程序中有图像厨房应用程序,我将所有图像都放入了drawable-hdpi文件夹中。我在活动中这样称呼图像: private Integer[] imageIDs = { R.drawable.wall1, R.drawable.wall2, R.drawable.wall3, R.drawable.wall4, R.drawable.wall5, R.drawable.wall6, R.drawable.wall7, R.drawable.wall8, R.drawable.wall9, R.drawable.wall10 }; 所以现在我想知道如何使用共享意图共享这样的图像,我把这样的共享代码放进去: Button shareButton = (Button) findViewById(R.id.share_button); shareButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Intent sharingIntent = new Intent(Intent.ACTION_SEND); Uri screenshotUri = Uri.parse(Images.Media.EXTERNAL_CONTENT_URI + "/" + imageIDs); sharingIntent.setType("image/jpeg"); sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri); startActivity(Intent.createChooser(sharingIntent, "Share image …
79 android  image  uri  share 

2
有没有更好的方法来从适配器获取对父RecyclerView的引用?
我有一个用例,需要RecyclerView从适配器内部(特别是在onBindViewHolder方法内部)对父级进行引用。到目前为止,我正在做的就是将它分配给argonCreateViewHolder传递的方法中的私有类成员,viewGroup parent如下所示: private ViewGroup mParent; @Override public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // inflater logic. mParent = parent; } 并引用父RecyclerView在onBindViewHolder这样的: @Override public void onBindViewHolder(ViewHolder holder, int position) { // binder logic. ((RecyclerView)mParent).blahBlahBlah(); } 有更好的方法吗?也许RecyclerView.Adapter有一种我可能错过的方式?

4
URLConnection.setDoOutput()究竟会影响什么?
有setDoOutput()在URLConnection。根据文件我应该 如果您打算将URL连接用于输出,请将DoOutput标志设置为true,否则将其设置为false。 现在,我正好面对这个问题-Java运行时将请求转换为POST一次setDoOutput(true)调用,而服务器仅响应GET请求。我想了解如果我setDoOutput(true)从代码中删除代码会发生什么。 这究竟会影响什么?假设我将其设置为false-现在可以做什么,现在不能做什么?我可以执行GET请求吗?在此方法的上下文中,“输出”是什么?

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.