ActionBar - setTitle seems to not to be called. All other things I'm doing with ActionBar (like HomeIsUp and so on) are going well, but setTitle - not.
Here is the code of a simple activity:
public class GuidelineDetails extends Activity implements OnClickListener {
String guideline_name;
String guideline_attachment;
public static TextView tv_title;
public static TextView tv_intro;
public static TextView tv_test;
public static WebView webview;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.guideline_detail);
getActionBar().setTitle("Privet");
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setDisplayShowTitleEnabled(false);
getActionBar().setIcon(R.drawable.listbullet);
///// some code
}
}
Why does it not set the title?
in manifest:
<activity
android:name=".GuidelineDetails"
android:configChanges="orientation"
android:label="Guideline"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Holo.Light" >
</activity>
in layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/guideline_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="1dp"
android:paddingLeft="10dp"
android:paddingRight="1dp"
android:paddingTop="35dp"
android:textSize="18dp"
android:textStyle="bold" />
</TableRow>
</TableLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.16"
android:orientation="vertical" >
<TableRow
android:id="#+id/tableRow4"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<WebView
android:id="#+id/webviewD"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</TableRow>
</LinearLayout>
</LinearLayout>
because of
getActionBar().setDisplayShowTitleEnabled(false);
change it to
getActionBar().setDisplayShowTitleEnabled(true);
Did you tried to set subTitle? Because in some cases if device screen is small in ActionBar you can see only the ActionBar icon. Try this.getActionBar().setTitle("Privet"); Hope this will help you!
I think it's because the Manifest file over rules it. I was having same issue with my icon, so I just had to change it in manifest file (android:label="Guideline"), or try not setting a label in Manifest if you have to set it grammatically.
Try to extend ActionBarActivity instead of Activity
in the manifest:
<activity android:name=".MessagingActivity"
android:label="MessagingActivity"
android:parentActivityName=".LoginActivity"
android:theme="#style/AppTheme.NoActionBar"></activity>
And in the Activity:
public class MessagingActivity extends AppCompatActivity {
private ImageView profileImage;
private TextView username;
private FirebaseUser firebaseUser;
private DatabaseReference referense;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_messaging);
Toolbar toolbarLcl = findViewById(R.id.toolbar);
setSupportActionBar(toolbarLcl );
ActionBar mActionBarLcl = getSupportActionBar();
mActionBarLcl.setTitle("username");
mActionBarLcl.setDisplayHomeAsUpEnabled(true);
toolbarLcl .setNavigationOnClickListener(v->{
finish();
});.....
and the xml:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MessagingActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay"
app:layout_constraintTop_toTopOf="parent"
>
<include layout="#layout/toolbar_messaging" />
</android.support.design.widget.AppBarLayout>
Related
Dependency reference: journeyapps/zxing-android-embedded
Description of the problem:
I'm new to Android Data binding & cannot bind the resource id zxing_viewfinder_view which is inside <merge> </merge>
Here is my code for understanding.
activity_scan_qr.xml
<LinearLayout
android:id="#+id/ll_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_below="#+id/ll_header"
android:background="#color/color_white"
android:gravity="center"
android:orientation="vertical">
<com.journeyapps.barcodescanner.DecoratedBarcodeView
android:id="#+id/zxing_barcode_scanner"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:zxing_scanner_layout="#layout/view_custom_qr_scanner"/>
</LinearLayout>
view_custom_qr_scanner.xml
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<com.journeyapps.barcodescanner.BarcodeView
android:id="#+id/zxing_barcode_surface"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:zxing_framing_rect_height="250dp"
app:zxing_framing_rect_width="250dp" />
<com.journeyapps.barcodescanner.ViewfinderView
android:id="#+id/zxing_viewfinder_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:zxing_possible_result_points="#color/zxing_custom_possible_result_points"
app:zxing_result_view="#color/zxing_custom_result_view"
app:zxing_viewfinder_laser="#color/zxing_custom_viewfinder_laser"
app:zxing_viewfinder_laser_visibility="true"
app:zxing_viewfinder_mask="#color/zxing_custom_viewfinder_mask" />
<TextView
android:id="#+id/zxing_status_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:background="#color/zxing_transparent"
android:text="Place a QR code inside the scan area."
android:textColor="#color/zxing_status_text" />
</merge>
ScanQRActivity.java
public class ScanQRActivity extends AppCompatActivity implements DecoratedBarcodeView.TorchListener {
public static final String TAG = ScanQRActivity.class.getSimpleName();
Context mContext;
Activity mActivity;
ActivityScanQrBinding binding;
ActionBar actionBar;
private CaptureManager capture;
boolean bFlashLight = false;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityScanQrBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
mContext = this;
mActivity = this;
capture = new CaptureManager(this, binding.zxingBarcodeScanner);
capture.initializeFromIntent(getIntent(), savedInstanceState);
capture.setShowMissingCameraPermissionDialog(true);
capture.decode();
changeLaserVisibility(true);
}
public void changeLaserVisibility(boolean visible) {
binding.zxingViewfinderView.setLaserVisibility(visible);
}
}
To use data binding you need to place your layout inside tag.
Your activity.xml
<layout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/ll_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_below="#+id/ll_header"
android:background="#color/color_white"
android:gravity="center"
android:orientation="vertical">
<com.journeyapps.barcodescanner.DecoratedBarcodeView
android:id="#+id/zxing_barcode_scanner"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:zxing_scanner_layout="#layout/view_custom_qr_scanner"/>
</LinearLayout>
</layout>
Your view_custom_qr_scanner.xml file should be
<layout>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<com.journeyapps.barcodescanner.BarcodeView
android:id="#+id/zxing_barcode_surface"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:zxing_framing_rect_height="250dp"
app:zxing_framing_rect_width="250dp" />
<com.journeyapps.barcodescanner.ViewfinderView
android:id="#+id/zxing_viewfinder_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:zxing_possible_result_points="#color/zxing_custom_possible_result_points"
app:zxing_result_view="#color/zxing_custom_result_view"
app:zxing_viewfinder_laser="#color/zxing_custom_viewfinder_laser"
app:zxing_viewfinder_laser_visibility="true"
app:zxing_viewfinder_mask="#color/zxing_custom_viewfinder_mask" />
<TextView
android:id="#+id/zxing_status_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"
android:background="#color/zxing_transparent"
android:text="Place a QR code inside the scan area."
android:textColor="#color/zxing_status_text" />
</merge>
</layout>
In your activity, create a new variable of type 'binding' that would be
private ViewCustomQrScannerBinding bindingCustomScanner
, now in your "OnCreate" under "binding = ActivityScanQrBinding.inflate (getLayoutInflater ());"
add this line
bindingCustomScanner = ViewCustomQrScannerBinding.bind (binding.root)
now when you call the properties of the new view, you call the new 'bindingCustomScanner'
There is a bottom_sheet_behavior button at the bottom of the screen, and when the keyboard shows up, it shows on the top of the keyboard. I want to keep it this way.
The problem is, when I tab the EditText to input, the button shows on the top of the keyboard, which overlaps half of the EditText like this:
So I want the EditText automatically scroll up a bit more to show itself wholy. I tried in MainActivity.java onCreate() {
mEditText.scrollTo(0, mEditText.getTop());
and tried
mEditText.scrollTo(0, mEditText.getTop() + 20);
// to try if it will scroll up more in this way. it didn't.
but the edittext is still half overlapped exactly as before when the keyboard appears. I guess I invoke the method in a wrong way?
The soft keyboard is not overlapping with the EditText, but the bottom button is. Is there anyway to programmatically scroll the EditText to right above the button when the keyboard showing?
the Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.robyn.myapplication">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity"
android:windowSoftInputMode="adjustResize"> // i tried make this "adjustPan" it behaves the same.
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.robyn.myapplication.MainActivity">
<LinearLayout
android:orientation="vertical"
android:layout_margin="8dp"
android:layout_width="match_parent"
android:layout_height="fill_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:background="#color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="200dp"/>
<TextView
android:text="Input:"
android:padding="4dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/input"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
<Button
android:id="#+id/save"
android:text="save"
android:backgroundTint="#color/colorAccent"
android:layout_alignParentBottom="true"
android:textColor="#FFFFFF"
app:layout_behavior="#string/bottom_sheet_behavior"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.CoordinatorLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
// bottom button overlaps edittext
private EditText mEditText;
private Button mButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
mEditText = (EditText)findViewById(R.id.input);
mEditText.scrollTo(0, mEditText.getTop());
mEditText.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
#Override
public void afterTextChanged(Editable s) {
}
});
mButton = (Button)findViewById(R.id.save);
mButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
}
}
Use paddingBottom to the parent of ScrollView (LinearLayout).
If Button height = 50dp, set paddingBottom="50dp" to LinearLayout.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_margin="8dp"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:paddingBottom="50dp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:background="#color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="200dp"/>
<TextView
android:text="Input:"
android:padding="4dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/input"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
<Button
android:id="#+id/save"
android:text="save"
android:backgroundTint="#color/colorAccent"
android:layout_alignParentBottom="true"
android:textColor="#FFFFFF"
app:layout_behavior="#string/bottom_sheet_behavior"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</android.support.design.widget.CoordinatorLayout>
I got an activity with many fragments. When i change fragments i need to change also and my toolbar declared in MainActivity.class. My problem is that i include a layout and didnt find a method to change this layout. How to change toolbars layout in this case?
MainActivity.class
#ContentView(R.layout.activity_main)
public class MainActivity extends RoboActionBarActivity {
#InjectView(R.id.tool_bar)
Toolbar toolbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setToolBar();
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new SplashFragment())
.commit();
} else {
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, new HomeFragment())
.commit();
}
}
private void setToolBar() {
setSupportActionBar(toolbar);
}
#Override
public void onAttachFragment(Fragment fragment) {
super.onAttachFragment(fragment);
String currentFragmentClass = fragment.getClass().getSimpleName();
if (currentFragmentClass.equals(getString(R.string.info_fragment))) {
//here i need to change and set onclicks
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.MainActivity">
<include
android:id="#+id/tool_bar"
layout="#layout/tool_bar" />
<View
android:id="#+id/shadow_view"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/tool_bar"
android:background="#ad8c22" />
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/shadow_view"
tools:context=".activities.MainActivity"
tools:ignore="MergeRootFrame" />
</RelativeLayout>
tool_bar.xml
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorToolBar"
>
<RelativeLayout
android:id="#+id/toolbar_main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:onClick="toggleSlidingMenu"
android:src="#mipmap/icon_sliding_menu" />
<ImageView
android:id="#+id/app_logo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#mipmap/jammboree" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/app_logo"
android:padding="5dp">
<ImageView
android:id="#+id/hotlist_bell"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:contentDescription="bell"
android:gravity="center"
android:padding="7dp"
android:src="#mipmap/icon_my_cart" />
<TextView
android:id="#+id/hotlist_hot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#id/hotlist_bell"
android:layout_alignTop="#id/hotlist_bell"
android:background="#drawable/rounded_square"
android:gravity="center"
android:minWidth="17sp"
android:padding="2dp"
android:text="2"
android:textColor="#ffffffff"
android:textSize="12sp" />
<TextView
android:id="#+id/myMoneyInMyPocket"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/hotlist_bell"
android:text="2000$"
android:textColor="#ffffff"
android:textSize="14sp"
android:textStyle="bold" />
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.Toolbar>
If I understood right, you want to change the toolbar whenever you change the Fragment the user is currently seeing, isn´t that right?
There is a very simple way to achieve this trough your XML. Let's say you want three different styled toolbars.
1) First, you create XML files for every toolbar you need.
2) Then you include every toolbar in to your activity_main.xml, like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.MainActivity">
<include
android:id="#+id/toolbar1"
layout="#layout/tool_bar1"
android:visibility="visible" />
<include
android:id="#+id/toolbar2"
layout="#layout/tool_bar2"
android:visibility="gone" />
<include
android:id="#+id/toolbar3"
layout="#layout/tool_bar3"
android:visibility="gone" />
// Here is the rest of your XML code
</RelativeLayout>
See how all three toolbar includes have the visibility property?
Well, now you can toy with this property, and show/hide the desired toolbar whenever you want/need to.
For example:
RelativeLayout mLayout = (RelativeLayout) getActivity().findViewById(R.id.my_main_layout);
Toolbar mToolbar1 = (Toolbar) mLayout.findViewById(R.id.toolbar1);
mToolbar1.setVisibility(View.GONE);
Toolbar mToolbar2 = (Toolbar) mLayout.findViewById(R.id.toolbar2);
mToolbar2.setVisibility(View.GONE);
Toolbar mToolbar3 = (Toolbar) mLayout.findViewById(R.id.toolbar3);
mToolbar3.setVisibility(View.VISIBLE);
And just change which one are you making visible, according to your needs.
Hope this helps.
I don`t think the method of #herrmartell is nice;
In my way,I have three Fragment in a Activity,I defined some different layout resources for a common toolbar xml,and load them in toolbar when I click different button; my code :
common_toolbar xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar">
<!-- your custom layout -->
</android.support.v7.widget.Toolbar>
activity_main_toolbar_common_view.xml
<TextView
android:id="#+id/action_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="迪士尼...ˇ"
android:textColor="#color/white"
android:textSize="#dimen/larget_text_size"
android:paddingLeft="10dp"
android:layout_alignParentStart="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
activity_main_toolbar_mine_view.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/mine"
android:textSize="#dimen/big_text_size"
android:textColor="#color/white"
android:gravity="center"
android:layout_centerInParent="true"/>
<ImageView
android:id="#+id/setting"
android:layout_width="#dimen/toolbar_icon_size"
android:layout_height="#dimen/toolbar_icon_size"
android:src="#drawable/toolbar_setting"
android:layout_alignParentRight="true"
/>
switchToolbar() method in Activity:
public void switchToolbar(int layout) {
if(currentToolbarLayout == layout){
return;
}
currentToolbarLayout = layout;
View v = getLayoutInflater().inflate(layout,null);
toolbar.removeAllViews();
toolbar.addView(v);
switch (layout){
case R.layout.activity_main_toolbar_common_view:
v.findViewById(R.id.action_location).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "跳到位置", Toast.LENGTH_SHORT).show();
}
});
break;
case R.layout.activity_main_toolbar_mine_view:
v.findViewById(R.id.setting).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "跳到设置", Toast.LENGTH_SHORT).show();
}
});
break;
}
}
I render my toolbar view in the onCreate() method of Activity:
ButterKnife.bind(this);
setSupportActionBar(toolbar);
switchToolbar(R.layout.activity_main_toolbar_common_view);
when I switch toolbar, I call:
switchToolbar(R.layout.activity_main_toolbar_mine_view);
I have some code in an Android app which was working fine but is now throwing an NPE when trying to locate a LinearLayout. The first line of the ReadRecords method below is returning a null for the linearLayoutRecords object, which is causing an NPE on the 2nd line:
public class SavedMealsActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_saved_meals);
// enable the home button
ActionBar actionBar = getActionBar();
actionBar.setHomeButtonEnabled(true);
// Read saved meal records from the database and display them
readRecords();
}
public void readRecords() {
LinearLayout linearLayoutRecords = (LinearLayout) findViewById(R.id.linearLayoutRecords);
linearLayoutRecords.removeAllViews();
The layout XML is here:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background"
android:orientation="vertical"
tools:context="com.ian.mealtimer.SavedMealsActivity$PlaceholderFragment" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/activity_saved_meals_textview1"
android:textSize="16sp"
android:textStyle="bold" />
<ScrollView
android:id="#+id/scrollViewRecords"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textViewRecordCount"
android:layout_margin="5dip"
android:padding="5dip" >
<LinearLayout
android:id="#+id/linearLayoutRecords"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>
Any ideas??
I created a sample application to test how sliding menu works. Shown below in the screenshot is what i get as of now. But when I click on the categories button (shown in image below) I should get a secondary menu as shown in the zomato app's screenshot below. How can I do this ? Am I proceeding in the correct way or not?
my SlidingFragmentActivity :
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
con = this;
setSlidingActionBarEnabled(false);
setContentView(R.layout.main);
sm = getSlidingMenu();
sm.setMode(SlidingMenu.RIGHT);
sm.setShadowDrawable(R.drawable.shadowright);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
sm.setBehindScrollScale(1.0f);
sm.setShadowWidthRes(R.dimen.shadow_width);
sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
sm.setFadeDegree(0.5f);
//sm.setSecondaryMenu(R.layout.properties);
//sm.setSecondaryShadowDrawable(R.drawable.shadow);
setTitle("Sliding Bar");
// set the Behind View
setBehindContentView(R.layout.menu_frame);
FragmentTransaction t = this.getSupportFragmentManager()
.beginTransaction();
mFrag = new SampleListFragment();
t.replace(R.id.menu_frame, mFrag);
t.commit();
}
my SampleListFragment :
public class SampleListFragment extends SherlockFragment {
private static final String[] Radio_buttons = new String[] { "Distance",
"Rating" };
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.list, container, false);
ListView radio_list = (ListView) view.findViewById(R.id.RadioList);
Button categories = (Button) view.findViewById(R.id.sampleButton);
radio_list
.setAdapter(new ArrayAdapter<String>(MainActivity.con,
android.R.layout.simple_list_item_single_choice,
Radio_buttons));
radio_list.setItemsCanFocus(true);
radio_list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
categories.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
MainActivity.sm.showSecondaryMenu();
}
});
return view;
}
}
main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Sliding menu demo...!!!" />
</RelativeLayout>
menu_frame.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/menu_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
list.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:paddingLeft="10dp"
android:text="SEARCH"
android:textColor="#FF3300"
android:textSize="20dp" >
</TextView>
</LinearLayout>
<RelativeLayout
android:id="#+id/searchTextLayout"
android:layout_width="match_parent"
android:layout_height="50dip"
android:layout_marginBottom="20dip"
android:layout_marginLeft="20dip"
android:layout_marginRight="20dip"
android:layout_marginTop="20dip" >
<ImageButton
android:id="#+id/searchTextButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:background="#685E5C"
android:scaleType="fitCenter"
android:src="#drawable/abs__ic_search" />
<EditText
android:id="#+id/searchText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="#id/searchTextButton"
android:background="#drawable/background_black_border_full"
android:padding="8dp"
android:textColor="#android:color/white" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:paddingLeft="10dp"
android:text="SORT BY"
android:textColor="#FF3300"
android:textSize="20dp" >
</TextView>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="134dp" >
<ListView
android:id="#+id/RadioList"
android:layout_width="match_parent"
android:layout_height="fill_parent" >
</ListView>
</RelativeLayout>
<Button
android:id="#+id/sampleButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Categories" />
</LinearLayout>
</ScrollView>
SlidingMenu does NOT do this, zomato uses a custom implementation.
SlidingMenu will let you have a menu on the left and the right, but not two on either side.
I would look at using a view pager or a custom implementation. EitherWay I don't know of anything out of the box to do this. I might be worth looking at Android Views for inspiration.
It's a bit late, but still let me post my answer in case it will help someone in future. If you want to show another menu you can use
setMode(SlidingMenu.LEFT_RIGHT);
setSecondaryMenu(R.layout.yourSecondMenu);
and in your button click
showSecondaryMenu(true);
and perform your actions in that class.