小编Bat*_*kun的帖子

设置android中按钮的透明度

我想在android中使用不同透明度级别的按钮.我使用过"@android:color/transparent".但它使按钮100%透明.我需要一个70%的透明按钮.这是我正在处理的XML代码:

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:gravity="center" 
    android:layout_weight="1">

    <Button android:id="@+id/one" 
        android:text="@string/dtmf_1"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:layout_weight="1" 
        android:textColor="@color/white" ></Button>
    <Button android:id="@+id/two"  
        android:text="@string/dtmf_2"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:layout_weight="1"  
        android:textColor="@color/white" ></Button>
    <Button android:id="@+id/three" 
        android:text="@string/dtmf_3"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:layout_weight="1"  
        android:textColor="@color/white" ></Button>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

android button

24
推荐指数
6
解决办法
8万
查看次数

如何添加gridview setOnItemClickListener

我有一个带有81个按钮的GridView.我想将clicklistener添加到此gridview,但它不可用.我添加了OnItemClickListener,但它无法正常工作,我无法理解为什么.代码没有错误.唯一不起作用的是OnItemClickListener.

我的gridview子节点上有一个按钮(gridview_members.xml);

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>

<Button
    android:id="@+id/city"
    android:layout_width="183dp"
    android:layout_height="90dp"
    android:textSize="19sp"
    android:textStyle="bold"
    android:text="Code\n\nCity"
    android:gravity="center"
    android:background="@drawable/city_btn_tablet" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我的ImageAdapter类;

public class ImageAdapter extends BaseAdapter {
private Context mContext;

public ImageAdapter(Context c) {
    mContext = c;
}

public int getCount() {
    return 81;
}

public Object getItem(int position) {
    return null;
}

public long getItemId(int position) {
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View gridView;

    gridView …
Run Code Online (Sandbox Code Playgroud)

android android-gridview

14
推荐指数
2
解决办法
5万
查看次数

java.lang.RuntimeException:启动失败

我正在尝试使用MediaRecorder在我的一个活动中录制音频.部分代码如下所示.

File file = new File(AppConstants.MSGS_DIR, filename);
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(AudioSource.MIC);
recorder.setOutputFormat(OutputFormat.THREE_GPP);
recorder.setAudioEncoder(AudioEncoder.AMR_WB);
recorder.setOutputFile(file.getAbsolutePath());
try {
    recorder.prepare();
    recorder.start();
} catch (IOException e) {
    System.out.println("Exception: " + e.getMessage());
}
Run Code Online (Sandbox Code Playgroud)

我在清单文件中给出了以下权限.

<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
Run Code Online (Sandbox Code Playgroud)

但在行记录器.start()我得到运行时异常.Logcat显示以下错误消息.

09-23 15:47:54.462: E/AndroidRuntime(8697): FATAL EXCEPTION: main
09-23 15:47:54.462: E/AndroidRuntime(8697): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mypackage/com.mypackage.RecordingActivity}: java.lang.RuntimeException: start failed.
09-23 15:47:54.462: E/AndroidRuntime(8697):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2250)
09-23 15:47:54.462: E/AndroidRuntime(8697):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2300)
09-23 15:47:54.462: E/AndroidRuntime(8697): …
Run Code Online (Sandbox Code Playgroud)

android forceclose android-mediarecorder android-permissions

8
推荐指数
1
解决办法
2万
查看次数

使用Volley进行异步帐户身份验证

每一个人.

我正在使用AbstractAccountAuthenticator实现帐户身份验证器,我需要在函数getAuthToken中调用异步方法来验证用户身份.我的代码是这样的:

public class AccountAuthenticator extends AbstractAccountAuthenticator {
    ...
    @Override
    public Bundle getAuthToken( final AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options )
        throws NetworkErrorException 
    {
        final AccountManager accountManager = AccountManager.get(context);   
        String authToken = accountManager.peekAuthToken( account, authTokenType );   
        // !!!!
        if( TextUtils.isEmpty(authToken) ) {
            <<call asynchronous method to acquire token>>
            return null;  
        }
        // !!!!
        final Bundle result = new Bundle();
        result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
        result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type);
        result.putString(AccountManager.KEY_AUTHTOKEN, authToken);
        return result;
    }
    ...
}
Run Code Online (Sandbox Code Playgroud)

根据Google的'getAuthToken'方法文档:它返回一个Bundle结果,如果要通过响应返回结果,则返回null.结果将包含两种:
AccountManager.KEY_INTENT
AccountManager.KEY_ACCOUNT_NAME …

android asynchronous token accountmanager android-volley

5
推荐指数
1
解决办法
1205
查看次数

从xml充气android.support.v4.app.fragment的正确方法

请帮忙.

哪个是对的?

像这样:

<?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="horizontal" >

    <android.support.v4.app.fragment
        android:id="@+id/advertListFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:name="com.myapp.fragment.AdvertListFragment"/>
Run Code Online (Sandbox Code Playgroud)

或者像这样:

<?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="horizontal" >

    <fragment
        android:id="@+id/advertListFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:name="com.myapp.fragment.AdvertListFragment"/>
Run Code Online (Sandbox Code Playgroud)

没有前缀"android.support.v4".

我没有更多细节

android android-fragments android-support-library

4
推荐指数
1
解决办法
2934
查看次数

按通知两次打开相同的活动

如果我有一个被用户关闭的活动(用户按下主页,所以应用程序仍在应用程序堆栈中),然后他收到通知,当他按下它时,我开始一个活动,现在同一个活动打开了两次。我怎样才能防止这种情况发生?

我的代码:

PendingIntent contentIntent = PendingIntent.getActivity(this, 0, 
        new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);

NotificationManager mNotificationManager = (NotificationManager)
        this.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.logo)
            .setContentTitle("Title")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
            .setAutoCancel(true)
            .setLights(GCMSIntentService.PURPLE, 500, 500)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
            .setContentText(msg);

mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(1, mBuilder.build());
Run Code Online (Sandbox Code Playgroud)

android android-activity android-pendingintent google-cloud-messaging

4
推荐指数
1
解决办法
2195
查看次数

setTitle到AppCompatDialog不起作用

我正在尝试使用新AppCompat 22.1功能AppCompatDialog,但它显示我没有标题的对话框,但我正在使用方法setTitle.如果我改变了AppCompatDialogDialog一切工作正常.这是一个错误AppCompatDialog吗?

这是我的对话框代码:

final AppCompatDialog dialog = new AppCompatDialog(ctx);
dialog.setTitle(R.string.choose_mode);
dialog.setContentView(R.layout.dialog_with_list);

ListView listView = (ListView) dialog.findViewById(R.id.list_view);

List<ModeItemModel> modesList = new ArrayList<ModeItemModel>();
modesList.add(new ModeItemModel(GUI_MANUAL));
modesList.add(new ModeItemModel(GUI_GPS));
listView.setAdapter(new ModeItemsAdapter(ctx, R.layout.list_item_ico_with_text, modesList));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
        //Do Action

        dialog.cancel();
    }
});
dialog.setCancelable(true);
dialog.show();
Run Code Online (Sandbox Code Playgroud)

android dialog android-appcompat

4
推荐指数
1
解决办法
3624
查看次数

如何通过Internet连接检查主机连接

我想全面检查与互联网和域名或主机的连接.我用一种方法检查互联网连接,但我无法添加检查主机可用性.我的代码在这里;

public class InternetCheck{
    public static boolean isInternetAvailable(Context context)
    {
        NetworkInfo info = (NetworkInfo) ((ConnectivityManager)
        context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();

        if (info == null){
            Constants.connectionProblem = "Check your internet connection";
            return false;
        }
        else{
            return true;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我想在isInternetAvailable()方法中添加主机或域可用性检查.它必须返回false并设置Constant.connectionProblem = "Host is not available".因为,我将在我的主要活动上调用该方法,如果它返回false,我将显示一个显示Constants.connectionProblem的Toast.

android internet-connection

1
推荐指数
1
解决办法
1440
查看次数

数组名如何包含其地址以及其中的第一个元素?

输出:

a=1606416992, &a=1606416992,
*a=1, &(*a)=1606416992
Run Code Online (Sandbox Code Playgroud)

程序:

#include "stdio.h"
main()
{
    int a[4]={1,2,3,4};
    printf("a=%u, &a=%u, *a=%d, &(*a)=%u\n",a,&a,*a,&(*a));
}
Run Code Online (Sandbox Code Playgroud)

我知道数组名称是指向数组第一个元素的指针.但我怀疑是指针应该存储在某个地方,它应该有一个地址位置.如果是这样,如何存储位置"1606416992"元素"1"并且相同的"1606416992"是指向数组的指针的地址位置?

请帮忙澄清一下.

c pointers

1
推荐指数
1
解决办法
240
查看次数

片段滑出动画不起作用

我有一个 android 应用程序,我在其中单击按钮从一个片段加载另一个片段

Fragment fragment = new EditImagesFragment();
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction tran = fragmentManager.beginTransaction();
tran.setCustomAnimations(R.anim.push, R.anim.pop);
tran.replace(R.id.content_frame, fragment).addToBackStack(null).commit();
Run Code Online (Sandbox Code Playgroud)

我有推和弹出(滑入和滑出)类型的动画定义如下

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <objectAnimator
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="500"
        android:propertyName="x"
        android:valueFrom="1000"
        android:valueTo="0"
        android:valueType="floatType" />

</set>
Run Code Online (Sandbox Code Playgroud)
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <objectAnimator
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="500"
        android:propertyName="x"
        android:valueFrom="0"
        android:valueTo="-1000"
        android:valueType="floatType" />

</set>
Run Code Online (Sandbox Code Playgroud)

现在,当我加载片段时,它会按预期滑入,但是当我按下后退按钮并尝试返回时,滑出动画不起作用,我支持 v14 及以上 API 级别。任何人都可以发现问题吗?

谢谢

animation android fragment

1
推荐指数
1
解决办法
2805
查看次数

json解析在android中给出类型不匹配

我正在解析一个json字符串.当我运行我的代码时,我收到json异常,在从json对象获取json数组的点处显示"类型不匹配".这是我的代码

String dataFromLogin="{"catego":{"id":"2","fname":"Tashen Jazbi","uname":"tashen",
    "password":"123","pic_url":"","lati":"33.7167","longi":"73.0667","city":"Islamabad",
    "country":"Pakistan","mobid":"000000000000000","street":"xyz",
    "dateandtime":"2013-12-29 18:07:52"}}";

try {
    JSONObject jsonObj = new JSONObject(dataFromLogin);
    //JSONObject response = jsonObj.getJSONObject("catego");
    JSONArray contacts = jsonObj.getJSONArray("catego");
    for (int i = 0; i < contacts.length(); i++) {
        JSONObject c = contacts.getJSONObject(i);

        fullname = c.getString("fname");

        uname = c.getString("uname");
        pic_url = c.getString("pic_url");

        lat = c.getString("lati");
        lng = c.getString("longi");

        city = c.getString("city");

        country = c.getString("country");

        street= c.getString("street");
    }

} catch (JSONException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

我找不到哪里做错了.如果有人可以提供帮助,那么我们将非常感激.

谢谢 :)

java android json

0
推荐指数
1
解决办法
1788
查看次数