android-xml

How do you pass the gravity attribute via xml for a custom view?

妖精的绣舞 提交于 2019-12-13 14:16:58
问题 I'm trying to figure out how to pass android:gravity via xml for a custom view. The solution posted here (https://stackoverflow.com/a/3441986/413254) says to add the android:gravity attribute to the other attr's. When I do this, I end up with a warning saying: /Users/greg/dev/company/mobile/my_app/app/src/main/res/values/colors.xml Error:Attribute "android:gravity" has already been defined Error:Execution failed for task ':app:processStagingDebugResources'. com.android.ide.common.internal

Android: Inflate menu (add items to action bar) only on click of a button

烈酒焚心 提交于 2019-12-13 09:15:26
问题 I am trying to inflate a menu only onclick of a button in android. How do i achieve it without creating it automatically by calling onCreateOptionsMenu. I want the menu to appear only after button is click. 回答1: First add this icon in you action R.menu... file and set the visibility as false. Have a boolean instance variable in our java file. private boolean isTickVisible = false; Then you need to override OnPrepareOptions menu like below and set the visibility of the tick menu. @Override

Create gridlayout. [closed]

两盒软妹~` 提交于 2019-12-13 08:27:15
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I need to create a layout like this: , I'm trying to do this using gridlayout, but it I cannot find the correct method. Can anyone please give me some guidance? Thanks! 回答1: I guess that the most straightforward way is combining horizontal and vertical LinearLayouts , setting different weights to its subviews.

Can't load data properly from xml file to Spinner

一个人想着一个人 提交于 2019-12-13 07:05:23
问题 I have listgender.xml file like this: <gender> <sex>male</sex> <sex>female</sex> </gender> This is spinner_data.xml for spinner: <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/tv_spinner" android:textColor="#ff0004" android:textSize="14sp" xmlns:android="http://schemas.android.com/apk/res/android" /> This is ClassGender : public class ClassGender { private String sex; public String getSex() { return sex; } public void setSex(String sex) {

Relative layout - stick buttons to bottom

淺唱寂寞╮ 提交于 2019-12-13 06:58:09
问题 I have a relative layout with two sub relative layouts: The first sub layout contains two text views, the second sub relative layout is below the first sub relative layout. However when I design all looks fine. When rendered on phone the buttons don't align to the second sub relative layouts bottom. Here is my code: <RelativeLayout android:id="@+id/relative_txt" android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_alignBottom="@+id/relative_img" android

Android - When and for which purpose we use the following prefixes in android xml file?

血红的双手。 提交于 2019-12-13 06:31:49
问题 I am new to android development and confused about the following prefixes: xmlns:android xmlns:app xmlns:tools android:something app:something tool:something I am confused about them because sometimes I use one, and android studio marks it as red underline which means i should use another one, and when sometimes i use another one android studio marks it with red line which means i should use the other one and so on, which makes me confused. And even in some cases i noticed that we are not

trouble accessing inflated ratingBar in Android

江枫思渺然 提交于 2019-12-13 06:27:16
问题 I have an async task that check if a user has a certain item, by checking a database. If they have an item then I inflate a rating bar, if not I inflate a button so they can add the item. I inflate the rating bar in an class which extends asyncTask with: //inflate star rater LayoutInflater mInflater = (LayoutInflater)c.getSystemService(Context.LAYOUT_INFLATER_SERVICE); LinearLayout addButton = (LinearLayout)((Activity) c).findViewById(R.id.addBeerLayout); addButton.addView(mInflater.inflate(R

Reading Local XML - Source Not Found

扶醉桌前 提交于 2019-12-13 04:28:36
问题 I am trying to read a resource of an XML file but I am getting error "Source Not Found", I am pasting my code beneath, please tell me where I am doing wrong public void ParseXmlFile() { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { DocumentBuilder db = dbf.newDocumentBuilder(); dom = db.parse((InputStream) context.getResources().getXml(R.xml.wrist)); } catch (ParserConfigurationException pce) { pce.printStackTrace(); } catch (SAXException se) { se.printStackTrace();

read external XML files in Android

泪湿孤枕 提交于 2019-12-13 03:22:39
问题 how to read this type of data of an external XML file in android app and set in views <?XML version="1.0"?> <OKV r="129120190116115414009" a="Address" g="male" m="123456" e="email" d="14021996" i="imagelink" n="My Name" v="1"/> 回答1: There are three way to parse an XML in Android DOM Parsers SAX Parsers XMLPullParser Follow these steps First, add permission of READ_EXTERNAL_STORAGE in your manifest file <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> Then check

Children views having equal height

做~自己de王妃 提交于 2019-12-13 02:23:27
问题 I have a horizontal LinearLayout with two buttons with text inside. The LinearLayout 's and the buttons layout_height is wrap_content . The text of one of the two buttons takes two lines unlike the other's which takes one line. So at the end one of the buttons has a bigger height than the other which is something that I don't want. I know how to solve this programmatically. So the reason I making this question is to know whether I can solve this through xml. One possible solution is, for the