Questions tagged «android»

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

13
Android Webview-完全清除缓存
我的一个活动中有一个WebView,加载网页时,该页面从Facebook收集一些背景数据。 我所看到的是,每次打开和刷新应用程序时,应用程序中显示的页面都是相同的。 我尝试将WebView设置为不使用缓存,并清除WebView的缓存和历史记录。 我在这里也遵循了建议:如何为WebView清空缓存? 但是这些都不起作用,没有人有任何想法可以克服这个问题,因为它是我应用程序的重要组成部分。 mWebView.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { if(progress >= 100) { mProgressBar.setVisibility(ProgressBar.INVISIBLE); } else { mProgressBar.setVisibility(ProgressBar.VISIBLE); } } }); mWebView.setWebViewClient(new SignInFBWebViewClient(mUIHandler)); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.clearHistory(); mWebView.clearFormData(); mWebView.clearCache(true); WebSettings webSettings = mWebView.getSettings(); webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); Time time = new Time(); time.setToNow(); mWebView.loadUrl(mSocialProxy.getSignInURL()+"?time="+time.format("%Y%m%d%H%M%S")); 因此,我实现了第一个建议(尽管将代码更改为递归的) private void clearApplicationCache() { …
111 android  caching  webview 

10
当按BACK按钮时,setResult不起作用
我试图在按下BACK按钮后设置setResult。我打电话给onDestroy Intent data = new Intent(); setResult(RESULT_OK, data) 但是当涉及到 onActivityResult(int requestCode, int resultCode, Intent data) 结果代码为0(RESULT_CANCELED),数据为“空”。 那么,如何传递以“返回”按钮终止的活动的结果?
111 android 

12
使用改造使用GSON获取嵌套的JSON对象
我正在使用Android应用程序中的API,所有JSON响应均如下所示: { 'status': 'OK', 'reason': 'Everything was fine', 'content': { < some data here > } 问题是,我所有的POJO有status,reason字段,里面content领域是真正的POJO我想要的。 有什么方法可以创建Gson的自定义转换器来提取始终的content字段,因此改造会返回适当的POJO?
111 java  android  json  gson  retrofit 


13
如何在RecyclerView中更新/刷新特定项目
我正在尝试刷新中的特定项目RecyclerView。 故事:每当用户单击项目时,都会显示AlertDialog。用户可以通过单击确定按钮键入一些文本。我想在此项目中显示此文本并显示不可见ImageView-以XML和适配器声明ViewHolder- 我在AlertDialog正按钮中使用了此功能来更新项目: private void updateListItem(int position) { View view = layoutManager.findViewByPosition(position); ImageView medicineSelected = (ImageView) view.findViewById(R.id.medicine_selected); medicineSelected.setVisibility(View.VISIBLE); TextView orderQuantity = (TextView) view.findViewById(R.id.order_quantity); orderQuantity.setVisibility(View.VISIBLE); orderQuantity.setText(quantity + " packet added!"); medicinesArrayAdapter.notifyItemChanged(position); } 但是,此代码不仅更改了通过位置的itemView,而且还更改了其他一些itemView! 我应该如何通过单击正确更改特定的itemView?


5
Android-在LinearLayout中水平居中放置TextView
我有以下基本布局 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/title_bar_background"> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:textAppearance="?android:attr/textAppearanceLarge" android:padding="10dp" android:text="HELLO WORLD" /> </LinearLayout> <LinearLayout> 看起来xml是正确的,但文本在左侧对齐。textview占据了父级的整个宽度,并且将textview设置为居中。不确定是什么问题...

11
在Android屏幕上更改对话框的位置
我AlertDialog在Activity中做了一个简单的说明: View view = layoutInflater.inflate(R.layout.my_dialog, null); AlertDialog infoDialog = new AlertDialog.Builder(MyActivity.this) .setView(view) .create(); infoDialog.show(); 使用以上代码,对话框将显示在屏幕中心(大约)。 我想知道,如何自定义对话框位置以使其显示在顶部操作栏下方?(是否有改变重力或对话框的内容?)以及如何根据我的代码进行操作?

9
如何更改Android 5.0的DatePicker对话框颜色
是否可以更改android 5.0的datepicker(以及timepicker)配色方案? 我尝试设置重点色,但这不起作用(带和不带android:): <!-- colorPrimary is used for the default action bar background --> <item name="colorPrimary">@color/purple</item> <!-- colorPrimaryDark is used for the status bar --> <item name="colorPrimaryDark">@color/purple_tint</item> <!-- colorAccent is used as the default value for colorControlActivated which is used to tint widgets --> <item name="colorAccent">@color/purple_tint</item> 从原始: 对于这样的事情:

19
NestedScrollView中的ViewPager
我需要创建一个类似于Google Newsstand的界面,该界面是一种在折叠的标题(垂直滚动)上的ViewPager(水平滚动)。我的要求之一是使用Google IO 2015上提供的新设计支持库。(http://android-developers.blogspot.ca/2015/05/android-design-support-library.html) 基于Chris Banes(https://github.com/chrisbanes/cheesesquare)创建的示例,我已经达到了可以执行折叠行为的程度,但是具有基本的LinearLayout(无水平滚动)。 我试图用ViewPager替换LinearLayout,但出现黑屏。我玩过:宽度,重量和各种视图组,但是..仍然是空白屏幕。似乎ViewPager和NestedScrollView彼此不喜欢。 我通过使用Horizo​​ntalScrollView尝试了一种解决方法:它可以工作,但是我放弃了PagerTitleStrip功能的好处,也没有将注意力集中在单个面板上(我可以在两个面板之间水平停​​止)。 现在,我不再有任何想法,如果有人可以引导我找到解决方案... 谢谢 这是我最新的布局文件: <?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="@dimen/header_height" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> <android.support.design.widget.CollapsingToolbarLayout android:layout_width="match_parent" android:layout_height="match_parent" app:contentScrim="?attr/colorPrimary" app:expandedTitleMarginEnd="64dp" app:expandedTitleMarginStart="48dp" app:layout_scrollFlags="scroll|exitUntilCollapsed"> <include layout="@layout/part_header" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_collapseMode="parallax"/> <android.support.v7.widget.Toolbar android:id="@+id/activity_main_toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" app:layout_collapseMode="pin" app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <android.support.v4.widget.NestedScrollView android:id="@+id/activity_main_nestedscrollview" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <android.support.v4.view.ViewPager …

8
使用okHttp信任所有证书
为了进行测试,我试图将套接字工厂添加到我的okHttp客户端中,该客户端工厂在设置代理时会信任所有内容。这已经做过很多次了,但是我对可信任套接字工厂的实现似乎缺少了一些东西: class TrustEveryoneManager implements X509TrustManager { @Override public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException { } @Override public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException { } @Override public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } } OkHttpClient client = new OkHttpClient(); final InetAddress ipAddress = InetAddress.getByName("XX.XXX.XXX.XXX"); // some IP …

20
清除意图
我的Android应用被传递信息的意图(状态栏中的待定意图)调用。 当我按下主屏幕按钮并按住主屏幕按钮重新打开我的应用程序时,它将再次调用该意图,并且相同的附加功能仍然存在。 @Override public void onSaveInstanceState(Bundle savedInstanceState) { super.onSaveInstanceState(savedInstanceState); } @Override public void onRestoreInstanceState(Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); } 这是不按预期运行的代码 String imgUrl; Bundle extras = this.getIntent().getExtras(); if(extras != null){ imgUrl = extras.getString("imgUrl"); if( !imgUrl.equals(textView01.getText().toString()) ){ imageView.setImageDrawable( getImageFromUrl( imgUrl ) ); layout1.setVisibility(0); textView01.setText(imgUrl);//textview to hold the url } } 我的意图是: public void …

4
从视图中删除所有子视图
如何从窗口小部件中删除所有子视图?例如,我有一个GridView,并动态地将许多其他LinearLayouts填充到其中。稍后在我的应用程序中,我希望重新开始使用该GridView并清除其所有子视图。我该怎么做?TIA。
111 android 

5
什么是Android MultiDex?
关于MultiDex的文章很多。有时,我遇到了一些错误已解决,包括multiDexEnabled true在defaultConfig我的build.gradle部分中。 但是,此功能到底是什么?有什么使用场景?


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.