我以前没有这个问题.当我尝试将Android Studio更新为2.3时,我得到了这个:
Studio does not have write access to /private/var/folders/00/n4yy8fsx0njck05bfll1t3_w0000gn/T/AppTranslocation/2D9E214E-60BE-41D9-9843-3536E011FD7E/d/Android Studio.app/Contents. Please run it by a privileged user to update.
Run Code Online (Sandbox Code Playgroud)
我所在的帐户是管理员帐户,我也尝试提供对该目录的完全访问权限.
chmod -R 777 /private/var/....
Run Code Online (Sandbox Code Playgroud)
但没有任何效果.任何帮助都感激不尽.
编辑:::请参考下面的答案......
题:::
我在Android中使用Fragments非常新,我完全搞砸了.
我只是想构建一个使用Fragments的简单示例应用程序.我的情况是,我的主要活动中有两个片段.第一个片段有一个edittext和一个按钮.第二个片段有一个textview.当我在edittext中输入名称并单击按钮时,第二个片段中的textview应显示在第一个片段的edittext中输入的名称.
我正在使用片段的静态分配(在XML中分配片段).
请参考下面的XML文件和代码......
activity_main.xml中
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="@+id/fragment_content_1"
android:name="com.example.fragmentexample.fragment_fragment_1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</fragment>
<fragment
android:id="@+id/fragment_content_2"
android:name="com.example.fragmentexample.fragment_fragment_2"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!-- Preview: layout=@layout/fragment_basic -->
</fragment>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
fragment_fragment_1.XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/edtxtPersonName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
<Button
android:id="@+id/btnSayHi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Say Hi" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
fragment_fragment_2.XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/txtViewResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I will say Hi" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
Java文件::: …
我试图了解Volley的图像缓存.我在里面有一个带有gridview的片段,它将加载大约12-30个图像.从服务器检索图像,我使用NetworkImageView加载这些图像.
我能够在NetworkImageView中显示图像,一切正常.但是,当我从一个改变fragment到另一个并回到之前的片段时LogCat,我看到Volley正试图再次获取图像.
我读Volley自动处理图像缓存.当图像缓存在第一个时fragment,为什么它会再次尝试获取图像,当我从第二个到第一个回来时?首先,LogCat数据是否显示了Volley的图像请求?或者是其他东西...
以下是我的代码:
在onCreate()
queue = Volley.newRequestQueue(getActivity());
imageLoader = new ImageLoader(queue, new ImageLoader.ImageCache() {
private final LruCache<String, Bitmap> mCache = new LruCache<String, Bitmap>(
10);
public void putBitmap(String url, Bitmap bitmap) {
mCache.put(url, bitmap);
}
public Bitmap getBitmap(String url) {
return mCache.get(url);
}
});
Run Code Online (Sandbox Code Playgroud)
第一次加载片段时的Logcat:
02-18 14:21:20.724: D/Volley(14713): [4944] BasicNetwork.logSlowRequests: HTTP response for request=<[ ] http://xx.files.wordpress.com/2014/02/screen-shot-2014-02-17-at-11-57-29-pm.png 0x800c5bdc LOW 2> [lifetime=3782], [size=398563], [rc=200], [retryCount=0]
02-18 14:21:20.874: D/Volley(14713): [4943] BasicNetwork.logSlowRequests: HTTP response for …Run Code Online (Sandbox Code Playgroud) 我在StackOverflow中多次看到过这个问题,但我无法解决问题.所以伸出援助之手.请注意:我已经检查了其他问题,虽然我可以摆脱错误,但还有其他问题.
这是我现有的代码:
我的适配器类:
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
Context context;
private final int VIEW_TYPE_ITEM = 0;
private final int VIEW_TYPE_LOADING = 1;
private IOnLoadMoreListener mIOnLoadMoreListener;
private int visibleThreshold = 3;
private int lastVisibleItem, totalItemCount;
private int[] lastVisibleItems = new int[mStaggeredLayoutManager.getSpanCount()];
public RecyclerViewAdapter(Context context) {
this.context = context;
final StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) recyclerView.getLayoutManager();
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
totalItemCount = staggeredGridLayoutManager.getItemCount();
lastVisibleItems = staggeredGridLayoutManager.findLastVisibleItemPositions(new int[mStaggeredLayoutManager.getSpanCount()]);
if (staggeredGridLayoutManager.getSpanCount() == …Run Code Online (Sandbox Code Playgroud) 我在WebView中加载一个网页.网页上有一个链接,在桌面上会下载文件,但在应用程序中,链接应显示Toast,表示该应用程序的链接已禁用.
href单击链接时,我不确定如何从锚标记中获取值.
<a class="btn btn-primary" download="http://xx.xxx.com/wp-content/uploads/2015/11/abc-27-15.mp3" href="http://xx.xxx.com/wp-content/uploads/2015/11/abc-27-15.mp3">
<i class="fa fa-download"></i> Download Audio</a>
Run Code Online (Sandbox Code Playgroud)
有人可以分享有关如何执行此操作的想法或任何示例代码.
编辑:1
这是我目前正在做的事情:
private static final String URL = "http://xx.xxx.com/wp-content/uploads/";
webView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
WebView.HitTestResult hr = ((WebView) v).getHitTestResult();
String extra = hr.getExtra();
if (extra != null && extra.startsWith(URL) && extra.endsWith(".mp3")) {
Log.d("WebviewActivity", "Extra: " + extra);
Log.d("WebviewActivity", "Contains URL");
return true;
}
}
return false;
}
});
Run Code Online (Sandbox Code Playgroud)
这种方法的问题是:当我点击链接时,我得到额外的网址.它工作正常,直到这里.但是,从下一次开始,无论我在哪里点击webview,都会返回相同的额外内容.因此,即使我点击了网址后点击图片,我也会获得相同的网址.不确定我做错了什么.或者这是正确的方法.
如果您需要任何细节,请告诉我.
编辑:2
private Handler mHandler = …Run Code Online (Sandbox Code Playgroud) 我正在使用GridLayout(支持)ImageView在我的应用程序中显示s.有3列5行.问题是细胞在GridLayout它们之间自动获得一些空间.我没有为细胞设置任何填充或边距.请参考下图.动态添加所有单元格,以下是添加这些单元格的方法.
获得屏幕宽度和高度:
Point size = new Point();
getWindowManager().getDefaultDisplay().getSize(size);
screenWidth = size.x;
screenHeight = size.y;
rowHeight = (int) (screenHeight * 0.2);
Run Code Online (Sandbox Code Playgroud)
将视图添加到GridLayout:
GridLayout.LayoutParams params = new GridLayout.LayoutParams(
getSpec(rowColumn[0]), getSpec(rowColumn[1]));
params.height = rowHeight;
if (rowColumn[1].equalsIgnoreCase("col_full")) {
params.width = (int) (screenWidth);
} else if (rowColumn[1].equalsIgnoreCase("col_two_part")) {
params.width = (int) (screenWidth * 0.6);
} else {
params.width = (int) (screenWidth * 0.3);
}
ImageButton image = (ImageButton) imageHashMap
.get(reOrderedButtonsListCopy.get(i));
image.setLayoutParams(params);
gridLayout.addView(image, params);
Run Code Online (Sandbox Code Playgroud)
XML布局:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.xx.xxx"
android:id="@+id/scrollView1"
android:layout_width="wrap_content" …Run Code Online (Sandbox Code Playgroud) 我的活动中有8个按钮.我正在寻找的是,按钮具有默认背景,当单击按钮时,背景颜色应该更改为其他颜色.这部分非常简单.但是,当我点击任何其他按钮时,第一个按钮的背景颜色应该变回默认颜色.我知道这将使用"选择器状态"完成,但我不太清楚如何实现它.我读的越多,我就越困惑.
现在,我拥有的xml如下:在drawable文件夹中
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/blue" android:state_pressed="true"/>
<item android:drawable="@color/dark_grey" android:state_focused="true"/>
<item android:drawable="@drawable/image_border"/>
</selector>
Run Code Online (Sandbox Code Playgroud)
xml中的drawable/image_border用于定义按钮的形状.下面是image_border.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="@color/dark_grey" />
<stroke
android:width="4dp"
android:color="@color/light_grey" />
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我如何更改xml以按照我需要的方式运行吗?
[编辑1]
以下所有答案都指向类似的解决方案.以下是我所做的更改.但是,当我按下按钮时,它会转到指定的颜色,但会立即变回默认颜色.
button_background_blue.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/image_border_blue" android:state_pressed="true"/>
<item android:drawable="@color/dark_grey" android:state_focused="true"/>
<item android:drawable="@drawable/image_border"/>
</selector>
Run Code Online (Sandbox Code Playgroud)
image_border_blue.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="@color/blue" />
<stroke
android:width="4dp"
android:color="@color/blue" />
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
</shape>
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
我想做这样的事情.有人能指出我正确的方向吗?
现在,我正在使用Scale Animation和FadeOut Animation.看起来像这样..
我如何为此添加背景颜色..另外请记住,我希望这可以从ICS/Jellybean工作
我的代码到现在为止......
fade_out_animation.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.1"
android:duration="100" />
</set>
Run Code Online (Sandbox Code Playgroud)
scale_up_animation.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:duration="100"
android:fromXScale="0.1"
android:fromYScale="0.1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1"
android:toYScale="1" />
</set>
Run Code Online (Sandbox Code Playgroud)
activity_main.xml - 只是相关部分
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<TextView
android:id="@+id/textView4"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_centerInParent="true"
android:layout_margin="8dp"
android:background="@drawable/shape_circle"
android:gravity="center"
android:text="004"
android:textColor="@color/light_gray"
android:textSize="18sp" />
<View
android:id="@+id/outer_view"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_centerInParent="true"
android:visibility="invisible"
android:background="@drawable/shape_circle_yellow"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
shape_circle.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="false" android:state_pressed="false" android:state_selected="false">
<shape android:shape="oval">
<solid android:color="@color/ash" /> <!-- Fill color -->
<stroke android:width="4dp" android:color="@color/medium_gray" …Run Code Online (Sandbox Code Playgroud) Android 2.3.3
我搜索过SO寻求解决方案,但我无法理解给出的解决方案.如果有人能够以简单的方式解释如何摆脱这个错误,我会很感激.
我在我的应用程序中使用ActionBarSherlock.我的基本主题Theme.Sherlock.Light适用于所有活动.对于一项活动,我希望我的活动看起来像一个对话框,因此我想使用Theme.Sherlock.Dialog.
这是我的清单文件的声明.
<activity
android:name="com.xxx.xx.x.Activity"
android:theme="@style/Theme.Sherlock.Dialog" >
</activity>
Run Code Online (Sandbox Code Playgroud)
但是我的XML中出现以下错误:error: Error: No resource found that matches the given name (at 'theme' with value '@style/Theme.Sherlock.Dialog')..我为什么要这个?我应该怎么做才能删除它?
我使用下面的代码来更改Indeterminate ProgressBar的颜色.这很有效,直到KitKat.但是在Lollipop上,它只是保持绿色.任何人都可以帮我解决这个问题.我想通过Java而不是XML来实现.
代码:这将微调颜色设置为粉红色
pd.getIndeterminateDrawable().setColorFilter(0xFFeA6060,
android.graphics.PorterDuff.Mode.MULTIPLY);
Run Code Online (Sandbox Code Playgroud)