Tag: android

ClassCastException android.widget.FrameLayout $ LayoutParams to android.support.v4.widget.DrawerLayout $ LayoutParams

我正在为Android导航抽屉工作。 根据我的要求,我要显示导航抽屉中的项目的gridview和listview。 我在布局xml文件中创build了一个linearLayout,并将两个小部件(网格视图和Listview)放置在LinearLayout中。 当我运行该文件时出现以下错误: java.lang.RuntimeException:无法启动活动ComponentInfo {com.example.navigationdrawer3 / com.example.navigationdrawer3.MainActivity}:java.lang.ClassCastException:android.widget.FrameLayout $ LayoutParams不能转换为android.support.v4。 widget.DrawerLayout $的LayoutParams 下面是我的java,logcat和NavigationDrawer布局文件: MainActivity.java public class MainActivity extends Activity { private DrawerLayout mDrawerLayout; private ListView mDrawerList; private ActionBarDrawerToggle mDrawerToggle; private CharSequence mDrawerTitle; //@SuppressWarnings("unused") private CharSequence mTitle; private String[] mGalaxyTitles; private GridView mDrawerGrid; private LinearLayout mDrawerLinear; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTitle = […]

Android的布局与9补丁背景打破

更新我的背景以使用9修补图像时遇到此问题。 在不同的屏幕上,使用不同大小的相同图像的布局很好,但是当我将图像更改为9补丁时,它会神秘地破坏整个布局。 以前的布局看起来像这样: 原始布局http://onik.org/android/layoutOk.png 。 当更改为9-patch时: 9-Patch image http://onik.org/android/layoutError.png 。 XML文件保持不变,只是PNG文件被更改。 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="@drawable/bg"> <TextView android:text="@string/title" android:id="@+id/login_title" android:layout_width="fill_parent" android:layout_height="40px" android:textSize="30px"> </TextView> <View android:id="@+id/login_underline" android:layout_width="wrap_content" android:layout_height="2px" android:background="#aaaaaa"> </View> <TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:stretchColumns="1" android:gravity="center" android:paddingLeft="10px" android:paddingRight="10px"> <TableRow> <TextView android:id="@+id/login_usernameLabel" android:text="@string/login_usernameLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingRight="5px"> </TextView> <EditText android:text="" android:id="@+id/login_username" android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="textEmailAddress" […]

“自动激活bundle com.android.ide.eclipse.adt时发生错误”

当到这里时:右键单击我的项目>属性> Android下面的错误发生。 这个错误发生在我去项目或任何一个库的属性>安卓(忽略BibleTriviaPro)。 这个错误似乎是从哪里来的。 我想不出任何我已经改变的东西,现在突然间,今天突然出现这个错误。 我怎样才能解决这个问题?

显示dex方法按包计数

我正在对付dex方法计数限制运行的android应用程序。 有一个简单的方法来显示按包分组的方法计数? 我可以得到总方法数,但我的应用程序有多个组件,我试图找出哪个组件是最大的贡献者。

你如何在Android上创build首选项活动和偏好片段?

当我正在关注一个老的教程( Créezdes应用程序灌输Android – > openclassroom )时,我被卡在PreferenceActivity类的这个弃用的方法addPreferencesFromResource(int id) 。 所以我的问题是: 在Android中创build首选项的新方法是什么?

将UTC转换为当前的语言环境时间

我正在从web服务下载一些JSON数据。 在这个JSON中,我有一些date/时间值。 UTC中的所有内容。 我怎样才能parsing这个datestring,所以结果date对象是在当前的语言环境? 例如:服务器返回“2011-05-18 16:35:01”,我的设备现在应该显示“2011-05-18 18:35:01”(GMT +2) 我目前的代码: SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date myDate = simpleDateFormat.parse(rawQuestion.getString("AskDateTime"));

如何使用Android gradle插件0.10.0或更高版本获得jacoco覆盖率报告?

我正在尝试使用Gradle Android插件0.10.2来获得testing覆盖率报告。 但是运行一些testing后我仍然无法获得覆盖报告。 (connectedAndroidTest)。 我的主要模块的build.gradle是: apply plugin: 'android' android { compileSdkVersion 19 buildToolsVersion "19.0.3" defaultConfig { minSdkVersion 8 targetSdkVersion 19 versionCode 1 versionName "1.0" } buildTypes { debug { testCoverageEnabled true } release { runProguard false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:19.+' } 而项目构buildgradle的buildscript部分是: buildscript { […]

将两个button设置为相同的宽度,而不考虑屏幕尺寸

好的,我有两个线性布局的button: <LinearLayout android:id="@+id/linearLayout1" android:layout_height="wrap_content" android:layout_width="fill_parent"> <Button android:id="@+id/aktiviraj_paket" android:text="Aktiviraj" android:layout_height="40sp" android:layout_width="160sp" android:background="@drawable/my_border3" android:onClick="myClickHandle"></Button> <Button android:id="@+id/deaktiviraj_paket" android:text="Deaktiviraj" android:layout_height="40sp" android:layout_width="fill_parent" android:background="@drawable/my_border3" android:onClick="myClickHandle"> </Button> </LinearLayout> 所以事情是,如果我在两个button上使用填充父项,它们是相互之间的一个,所以我做了第一个button160sp宽度,第二个是fill_parent。 如果在4英寸或更小的屏幕上显示,button的大小相同,但如果我在平板电脑(10英寸)上尝试此操作,则第一个button的宽度将保持为160sp,而第二个button的宽度将延伸到屏幕的末端(因为fill_parent)。 我可以做到这一点,所以无论屏幕大小如何,两个button都可以是大小的。

DialogFragment并强制显示键盘

我的DialogFragment有问题。 所以要创build我的视图,我使用在Android博客上描述的方法。 这是我的DialogFragment @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View myLayout = inflater.inflate(R.layout.dialog_connect, null); edit = (EditText) myLayout.findViewById(R.id.password_edit); edit.requestFocus(); getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_VISIBLE); return myLayout; } 如果我使用onCreateView(),它的工作原理,但我想创build一个AlterDialog并做到这一点,我有以下代码: @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Inflate and set the layout for the dialog // Pass null as the parent […]

如何限制EditText只接受字母数字字符

如何限制EditText仅接受字母数字字符,在EditText写字母和大写字符都显示为大写字母? <EditText android:id="@+id/userInput" android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="textMultiLine" android:minLines="3" > <requestFocus /> </EditText> 如果用户input小写字母“abcd”, EditText应该自动显示大写“ABCD”而不需要将键盘限制为大写。