Questions tagged «android»

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


4
停止handler.postDelayed()
我通过new Handler()。postDelayed(new Runnable().....来调用多个Handler。当我单击返回时如何停止它? public class MyActivity extends AppCompatActivity implements OnClickListener { private Button btn; private Handler handler; private Runnable myRunnable; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); btn = (Button) findViewById(R.id.trainingsstart); btn.setOnClickListener(this); } @Override public void onClick(View v) { Handler handler = new Handler(); Runnable myRunnable = new Runnable() { …

12
如何在Android Studio中创建测试?
刚刚下载了基于Intellij Idea的Android Studio。 一个人将如何创建测试? 我注意到有一个用于创建测试模块的选项,但这似乎没有任何作用,仅使用src创建一个新项目 我还尝试按热键CTRL + AlT + T,该键可以在现有类上创建单元测试,但似乎想将其放置在当前项目中。当然这对TDD没有帮助 有人在这里有经验吗?

3
不建议使用的ManagedQuery()问题
我有这种方法: public String getRealPathFromURI(Uri contentUri) { String[] proj = { MediaStore.Images.Media.DATA }; Cursor cursor = managedQuery(contentUri, proj, null, null, null); int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } 不幸的是,编译器向我显示了以下问题: Cursor cursor = managedQuery(contentUri, proj, null, null, null); 因为managedQuery()不推荐使用。 不使用该如何改写此方法managedQuery()?
109 java  android  deprecated 


7
Android中的圆形渐变
我正在尝试使渐变从屏幕中间以白色发出,并随着其向屏幕边缘移动而变为黑色。 当我像这样制作“正常”渐变时,我一直在尝试不同的形状: <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <gradient android:startColor="#E9E9E9" android:endColor="#D4D4D4" android:angle="270"/> </shape> 使用“卵形”形状时,我至少具有圆形形状,但没有渐变效果。我该如何实现?”
109 android  gradient 

7
将Uri转换为String
是否可以将转换Uri为String,反之亦然?因为我想将Uri转换String后的内容通过传递到另一个活动中intent.putextra(),如果不可能的话,有人可以建议我如何将选定的内容传递Uri到另一个活动中吗?
109 android  string  uri 

5
ConstraintLayout:以编程方式更改约束
我需要帮助ConstraintSet。我的目标是在代码中更改视图的约束,但是我无法弄清楚如何正确执行此操作。 我有4 TextView秒一ImageView。我需要将ImageView约束设置为之一TextView。 check_answer4 = (TextView) findViewById(R.id.check_answer4); check_answer1 = (TextView) findViewById(R.id.check_answer1); check_answer2 = (TextView) findViewById(R.id.check_answer2); check_answer3 = (TextView) findViewById(R.id.check_answer3); correct_answer_icon = (ImageView) findViewById(R.id.correct_answer_icon); 如果第一个答案是正确的,我需要的一组约束ImageView来 app:layout_constraintRight_toRightOf="@+id/check_answer1" app:layout_constraintTop_toTopOf="@+id/check_answer1" 如果第二个答案是正确的,我需要将约束设置ImageView为 app:layout_constraintRight_toRightOf="@+id/check_answer2" app:layout_constraintTop_toTopOf="@+id/check_answer2" 等等。

3
如何在Android应用程序中激活“共享”按钮?
我想向我的Android应用程序添加“共享”按钮。 像那样 我添加了“共享”按钮,但该按钮未激活。我单击,但什么都没有发生。 我在MainActivity.java中的代码: private ShareActionProvider mShareActionProvider; @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.share_menu, menu); getMenuInflater().inflate(R.menu.main, menu); MenuItem item = menu.findItem(R.id.share_menu); mShareActionProvider = (ShareActionProvider) menu.findItem(R.id.share_menu).getActionProvider(); mShareActionProvider.setShareIntent(getDefaultShareIntent()); return true; } { Intent sharingIntent = new Intent(Intent.ACTION_SEND); sharingIntent.setType("text/plain"); sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Text"); sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject"); startActivity(Intent.createChooser(sharingIntent, "Share using")); } 我想在第一个选项卡(first_tab.xml)或第二个选项卡(second_tab.xml)中共享文本。 标签(xml)中的代码(如果需要): <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" …
109 java  android  xml  button  share 

21
将秒值转换为小时分钟秒?
我一直在尝试将秒值(在BigDecimal变量中)转换为editText之类的字符串,例如“ 1小时22分33秒”或类似的内容。 我已经试过了: String sequenceCaptureTime = ""; BigDecimal roundThreeCalc = new BigDecimal("0"); BigDecimal hours = new BigDecimal("0"); BigDecimal myremainder = new BigDecimal("0"); BigDecimal minutes = new BigDecimal("0"); BigDecimal seconds = new BigDecimal("0"); BigDecimal var3600 = new BigDecimal("3600"); BigDecimal var60 = new BigDecimal("60"); (我有一个roundThreeCalc,它是以秒为单位的值,所以我尝试在这里进行转换。) hours = (roundThreeCalc.divide(var3600)); myremainder = (roundThreeCalc.remainder(var3600)); minutes …


10
在按钮上播放声音单击android
单击时如何获得一个按钮来播放原始声音?我刚刚创建了一个带有id的按钮button1,但是无论我写什么代码,都错了。 import android.media.MediaPlayer; public class BasicScreenActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_basic_screen); } Button one = (Button)this.findViewById(R.id.button1); MediaPlayer = mp; mp = MediaPlayer.create(this, R.raw.soho); zero.setOnCliclListener(new View.OnClickListener() ) @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if …

4
Android:创建具有多个选择选项的弹出窗口
我一直在寻找解决方法,以找出如何创建弹出式窗口或具有4个选项的对话框。 我在Android开发人员网站上看到了这张照片: 有谁知道如何编写类似于右侧的代码?我的文字旁边不需要任何图标,我只需要能够从4个选项中进行选择即可。
109 android  menu  dialog  popup 


21
加载广告失败:3
我正在使用DoubleClick在我的Android应用程序中设置广告,但无法显示最终广告,有人可以帮我吗? 当我通过添加“ .addTestDevice(” xxx ...“)”来测试广告时,我得到了测试广告,但是当我删除此行时,出现了以下错误: W /广告:广告服务器未填充 W /广告:无法加载广告:3 我将广告设置为: PublisherAdRequest adRequest = new PublisherAdRequest.Builder().build(); mPublisherAdView.loadAd(adRequest); 我的PublisherView看起来像这样: <com.google.android.gms.ads.doubleclick.PublisherAdView android:id="@+id/pronostics_ad" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" ads:adSize="BANNER" ads:adUnitId="@string/ad_unit_pronostic"> </com.google.android.gms.ads.doubleclick.PublisherAdView> 有什么事吗 预先感谢您的回答。

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.